@shopify/cli-kit 3.32.0 → 3.32.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.
Files changed (108) hide show
  1. package/dist/api.d.ts +2 -5
  2. package/dist/api.js +2 -5
  3. package/dist/api.js.map +1 -1
  4. package/dist/http/fetch.js +1 -1
  5. package/dist/http/fetch.js.map +1 -1
  6. package/dist/http.d.ts +0 -1
  7. package/dist/http.js +0 -1
  8. package/dist/http.js.map +1 -1
  9. package/dist/index.d.ts +0 -5
  10. package/dist/index.js +0 -5
  11. package/dist/index.js.map +1 -1
  12. package/dist/npm.js +1 -1
  13. package/dist/npm.js.map +1 -1
  14. package/dist/private/node/analytics.js +2 -2
  15. package/dist/private/node/analytics.js.map +1 -1
  16. package/dist/private/node/api/graphql.d.ts +5 -0
  17. package/dist/private/node/api/graphql.js +63 -0
  18. package/dist/private/node/api/graphql.js.map +1 -0
  19. package/dist/{api/common.d.ts → private/node/api/headers.d.ts} +3 -8
  20. package/dist/{api/common.js → private/node/api/headers.js} +20 -60
  21. package/dist/private/node/api/headers.js.map +1 -0
  22. package/dist/private/node/ui/components/FullScreen.js +11 -9
  23. package/dist/private/node/ui/components/FullScreen.js.map +1 -1
  24. package/dist/private/node/ui/components/SelectPrompt.js +15 -3
  25. package/dist/private/node/ui/components/SelectPrompt.js.map +1 -1
  26. package/dist/private/node/ui/components/Table.js +1 -1
  27. package/dist/private/node/ui/components/Table.js.map +1 -1
  28. package/dist/public/common/collection.js.map +1 -1
  29. package/dist/public/common/object.js +3 -3
  30. package/dist/public/common/object.js.map +1 -1
  31. package/dist/public/common/string.d.ts +55 -1
  32. package/dist/public/common/string.js +93 -1
  33. package/dist/public/common/string.js.map +1 -1
  34. package/dist/public/node/api/admin.d.ts +11 -0
  35. package/dist/public/node/api/admin.js +70 -0
  36. package/dist/public/node/api/admin.js.map +1 -0
  37. package/dist/public/node/api/oxygen.d.ts +22 -0
  38. package/dist/public/node/api/oxygen.js +40 -0
  39. package/dist/public/node/api/oxygen.js.map +1 -0
  40. package/dist/{api → public/node/api}/partners.d.ts +11 -3
  41. package/dist/public/node/api/partners.js +40 -0
  42. package/dist/public/node/api/partners.js.map +1 -0
  43. package/dist/public/node/base-command.js +1 -1
  44. package/dist/public/node/base-command.js.map +1 -1
  45. package/dist/public/node/crypto.d.ts +42 -0
  46. package/dist/public/node/crypto.js +55 -0
  47. package/dist/public/node/crypto.js.map +1 -0
  48. package/dist/{template.d.ts → public/node/liquid.d.ts} +10 -2
  49. package/dist/{template.js → public/node/liquid.js} +18 -13
  50. package/dist/public/node/liquid.js.map +1 -0
  51. package/dist/public/node/os.d.ts +16 -0
  52. package/dist/{os.js → public/node/os.js} +33 -28
  53. package/dist/public/node/os.js.map +1 -0
  54. package/dist/public/node/presets.js +2 -2
  55. package/dist/public/node/presets.js.map +1 -1
  56. package/dist/public/node/ruby.d.ts +11 -7
  57. package/dist/public/node/ruby.js +89 -21
  58. package/dist/public/node/ruby.js.map +1 -1
  59. package/dist/public/node/tcp.d.ts +2 -0
  60. package/dist/public/node/tcp.js +9 -0
  61. package/dist/public/node/tcp.js.map +1 -1
  62. package/dist/public/node/toml.d.ts +15 -0
  63. package/dist/public/node/toml.js +20 -0
  64. package/dist/public/node/toml.js.map +1 -0
  65. package/dist/public/node/vscode.d.ts +14 -0
  66. package/dist/{vscode.js → public/node/vscode.js} +13 -7
  67. package/dist/public/node/vscode.js.map +1 -0
  68. package/dist/session/authorize.d.ts +4 -0
  69. package/dist/session/authorize.js +7 -2
  70. package/dist/session/authorize.js.map +1 -1
  71. package/dist/{api/identity.d.ts → session/identity-token-validation.d.ts} +0 -0
  72. package/dist/{api/identity.js → session/identity-token-validation.js} +1 -1
  73. package/dist/session/identity-token-validation.js.map +1 -0
  74. package/dist/session/schema.d.ts +18 -18
  75. package/dist/session/store.js +1 -1
  76. package/dist/session/store.js.map +1 -1
  77. package/dist/session.js +3 -3
  78. package/dist/session.js.map +1 -1
  79. package/dist/system.js +1 -1
  80. package/dist/system.js.map +1 -1
  81. package/dist/tsconfig.tsbuildinfo +1 -1
  82. package/dist/ui/inquirer/autocomplete.js +1 -1
  83. package/dist/ui/inquirer/autocomplete.js.map +1 -1
  84. package/package.json +2 -1
  85. package/dist/api/admin.d.ts +0 -3
  86. package/dist/api/admin.js +0 -56
  87. package/dist/api/admin.js.map +0 -1
  88. package/dist/api/common.js.map +0 -1
  89. package/dist/api/identity.js.map +0 -1
  90. package/dist/api/oxygen.d.ts +0 -5
  91. package/dist/api/oxygen.js +0 -30
  92. package/dist/api/oxygen.js.map +0 -1
  93. package/dist/api/partners.js +0 -44
  94. package/dist/api/partners.js.map +0 -1
  95. package/dist/http/graphql.d.ts +0 -13
  96. package/dist/http/graphql.js +0 -12
  97. package/dist/http/graphql.js.map +0 -1
  98. package/dist/os.d.ts +0 -11
  99. package/dist/os.js.map +0 -1
  100. package/dist/string.d.ts +0 -28
  101. package/dist/string.js +0 -77
  102. package/dist/string.js.map +0 -1
  103. package/dist/template.js.map +0 -1
  104. package/dist/toml.d.ts +0 -3
  105. package/dist/toml.js +0 -8
  106. package/dist/toml.js.map +0 -1
  107. package/dist/vscode.d.ts +0 -8
  108. package/dist/vscode.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"object.js","sourceRoot":"","sources":["../../../src/public/common/object.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,WAAW,CAAA;AAEjC,OAAO,EAAC,aAAa,EAAC,MAAM,QAAQ,CAAA;AAEpC,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAE9C;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAC9B,GAAgB,EAChB,GAAgB,EAChB,qBAAyF,kBAAkB;IAE3G,OAAO,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,EAAC,UAAU,EAAE,kBAAkB,EAAC,CAAC,CAAA;AAC9D,CAAC;AAED,SAAS,kBAAkB,CAAC,gBAA2B,EAAE,WAAsB;IAC7E,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,gBAAgB,EAAE,GAAG,WAAW,CAAC,CAAC,CAAC,CAAA;AACnE,CAAC;AAED;;;;;;;GAOG;AACH,gEAAgE;AAChE,MAAM,UAAU,MAAM,CACpB,MAAwC,EACxC,SAA+B;IAE/B,MAAM,YAAY,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAA;IAChD,OAAO,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;AACxC,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,SAAS,CACvB,GAAyB,EACzB,QAAoC;IAEpC,MAAM,eAAe,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAA;IACtD,OAAO,eAAe,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;AACvC,CAAC","sourcesContent":["import deepMerge from 'deepmerge'\nimport {Dictionary, ObjectIterator, ValueKeyIteratee} from 'lodash'\nimport {createRequire} from 'module'\n\nconst require = createRequire(import.meta.url)\n\n/**\n * Deep merges the two objects and returns a new object with the merge result.\n *\n * @param lhs - One of the objects to be merged.\n * @param rhs - Another object to be merged.\n * @param arrayMergeStrategy - Strategy used to merge the array typed fields. Union strategy is used by default to avoid\n * duplicated elements.\n * @returns A Javascrip tobject with th emerged objects.\n */\nexport function deepMergeObjects<T1, T2>(\n lhs: Partial<T1>,\n rhs: Partial<T2>,\n arrayMergeStrategy: (destinationArray: unknown[], sourceArray: unknown[]) => unknown[] = unionArrayStrategy,\n): T1 & T2 {\n return deepMerge(lhs, rhs, {arrayMerge: arrayMergeStrategy})\n}\n\nfunction unionArrayStrategy(destinationArray: unknown[], sourceArray: unknown[]): unknown[] {\n return Array.from(new Set([...destinationArray, ...sourceArray]))\n}\n\n/**\n * Creates an object composed of the `object` properties `predicate` returns\n * truthy for. The predicate is invoked with two arguments: (value, key).\n *\n * @param object- The source object.\n * @param predicate - The function invoked per property.\n * @returns Returns the new object.\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport function pickBy<T, S extends T>(\n object: Dictionary<T> | null | undefined,\n predicate?: ValueKeyIteratee<T>,\n): Dictionary<S> {\n const lodashPickBy = require('lodash/pickBy.js')\n return lodashPickBy(object, predicate)\n}\n\n/**\n * Creates an object with the same keys as object and values generated by running each own\n * enumerable property of object through iteratee. The iteratee function is\n * invoked with three arguments: (value, key, object).\n *\n * @param object - The object to iterate over.\n * @param callback - The function invoked per iteration.\n * @returns Returns the new mapped object.\n */\nexport function mapValues<T extends object, TResult>(\n obj: T | null | undefined,\n callback: ObjectIterator<T, TResult>,\n): {[P in keyof T]: TResult} {\n const lodashMapValues = require('lodash/mapValues.js')\n return lodashMapValues(obj, callback)\n}\n"]}
1
+ {"version":3,"file":"object.js","sourceRoot":"","sources":["../../../src/public/common/object.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,WAAW,CAAA;AAEjC,OAAO,EAAC,aAAa,EAAC,MAAM,QAAQ,CAAA;AAEpC,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAE9C;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAC9B,GAAgB,EAChB,GAAgB,EAChB,qBAAyF,kBAAkB;IAE3G,OAAO,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,EAAC,UAAU,EAAE,kBAAkB,EAAC,CAAC,CAAA;AAC9D,CAAC;AAED;;;;;;;GAOG;AACH,gEAAgE;AAChE,MAAM,UAAU,MAAM,CACpB,MAAwC,EACxC,SAA+B;IAE/B,MAAM,YAAY,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAA;IAChD,OAAO,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;AACxC,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,SAAS,CACvB,GAAyB,EACzB,QAAoC;IAEpC,MAAM,eAAe,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAA;IACtD,OAAO,eAAe,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;AACvC,CAAC;AAED,SAAS,kBAAkB,CAAC,gBAA2B,EAAE,WAAsB;IAC7E,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,gBAAgB,EAAE,GAAG,WAAW,CAAC,CAAC,CAAC,CAAA;AACnE,CAAC","sourcesContent":["import deepMerge from 'deepmerge'\nimport {Dictionary, ObjectIterator, ValueKeyIteratee} from 'lodash'\nimport {createRequire} from 'module'\n\nconst require = createRequire(import.meta.url)\n\n/**\n * Deep merges the two objects and returns a new object with the merge result.\n *\n * @param lhs - One of the objects to be merged.\n * @param rhs - Another object to be merged.\n * @param arrayMergeStrategy - Strategy used to merge the array typed fields. Union strategy is used by default to avoid\n * duplicated elements.\n * @returns A Javascrip tobject with th emerged objects.\n */\nexport function deepMergeObjects<T1, T2>(\n lhs: Partial<T1>,\n rhs: Partial<T2>,\n arrayMergeStrategy: (destinationArray: unknown[], sourceArray: unknown[]) => unknown[] = unionArrayStrategy,\n): T1 & T2 {\n return deepMerge(lhs, rhs, {arrayMerge: arrayMergeStrategy})\n}\n\n/**\n * Creates an object composed of the `object` properties `predicate` returns\n * truthy for. The predicate is invoked with two arguments: (value, key).\n *\n * @param object- The source object.\n * @param predicate - The function invoked per property.\n * @returns Returns the new object.\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport function pickBy<T, S extends T>(\n object: Dictionary<T> | null | undefined,\n predicate?: ValueKeyIteratee<T>,\n): Dictionary<S> {\n const lodashPickBy = require('lodash/pickBy.js')\n return lodashPickBy(object, predicate)\n}\n\n/**\n * Creates an object with the same keys as object and values generated by running each own\n * enumerable property of object through iteratee. The iteratee function is\n * invoked with three arguments: (value, key, object).\n *\n * @param object - The object to iterate over.\n * @param callback - The function invoked per iteration.\n * @returns Returns the new mapped object.\n */\nexport function mapValues<T extends object, TResult>(\n obj: T | null | undefined,\n callback: ObjectIterator<T, TResult>,\n): {[P in keyof T]: TResult} {\n const lodashMapValues = require('lodash/mapValues.js')\n return lodashMapValues(obj, callback)\n}\n\nfunction unionArrayStrategy(destinationArray: unknown[], sourceArray: unknown[]): unknown[] {\n return Array.from(new Set([...destinationArray, ...sourceArray]))\n}\n"]}
@@ -1,6 +1,60 @@
1
1
  export declare type RandomNameFamily = 'business' | 'creative';
2
2
  /**
3
- * @param family - Theme to use for the random name
3
+ * Generates a random name by combining an adjective and noun.
4
+ *
5
+ * @param family - Theme to use for the random name (business or creative).
4
6
  * @returns A random name generated by combining an adjective and noun.
5
7
  */
6
8
  export declare function getRandomName(family?: RandomNameFamily): string;
9
+ /**
10
+ * Given a string, it returns it with the first letter capitalized.
11
+ *
12
+ * @param str - String to capitalize.
13
+ * @returns String with the first letter capitalized.
14
+ */
15
+ export declare function capitalize(str: string): string;
16
+ /**
17
+ * Try to convert a string to an int, falling back to undefined if unable to.
18
+ *
19
+ * @param maybeInt - String to convert to an int.
20
+ * @returns The int if it was able to convert, otherwise undefined.
21
+ */
22
+ export declare function tryParseInt(maybeInt: string | undefined): number | undefined;
23
+ /**
24
+ * Transforms a matrix of strings into a single string with the columns aligned.
25
+ *
26
+ * @param lines - Array of rows, where each row is an array of strings (representing columns).
27
+ * @returns A string with the columns aligned.
28
+ */
29
+ export declare function linesToColumns(lines: string[][]): string;
30
+ /**
31
+ * Given a string, it transforms it to a slug (lowercase, hyphenated, no special chars, trimmed...).
32
+ *
33
+ * @param str - String to slugify.
34
+ * @returns The slugified string.
35
+ */
36
+ export declare function slugify(str: string): string;
37
+ /**
38
+ * Given a string, it returns it with the special regex characters escaped.
39
+ * More info: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping.
40
+ *
41
+ * @param str - String to escape.
42
+ * @returns The escaped string.
43
+ */
44
+ export declare function escapeRegExp(str: string): string;
45
+ /**
46
+ * Transform a string to camelCase.
47
+ */
48
+ export { camelCase as camelize } from 'change-case';
49
+ /**
50
+ * Transform a string to param-case.
51
+ */
52
+ export { paramCase as hyphenate } from 'change-case';
53
+ /**
54
+ * Transform a string to snake_case.
55
+ */
56
+ export { snakeCase as underscore } from 'change-case';
57
+ /**
58
+ * Transform a string to CONSTANT_CASE.
59
+ */
60
+ export { constantCase as constantize } from 'change-case';
@@ -1,4 +1,5 @@
1
1
  import { takeRandomFromArray } from './array.js';
2
+ import { unstyled } from '../../output.js';
2
3
  const SAFE_RANDOM_BUSINESS_ADJECTIVES = [
3
4
  'commercial',
4
5
  'profitable',
@@ -90,7 +91,9 @@ const SAFE_RANDOM_CREATIVE_NOUNS = [
90
91
  'tone',
91
92
  ];
92
93
  /**
93
- * @param family - Theme to use for the random name
94
+ * Generates a random name by combining an adjective and noun.
95
+ *
96
+ * @param family - Theme to use for the random name (business or creative).
94
97
  * @returns A random name generated by combining an adjective and noun.
95
98
  */
96
99
  export function getRandomName(family = 'business') {
@@ -106,4 +109,93 @@ export function getRandomName(family = 'business') {
106
109
  };
107
110
  return `${takeRandomFromArray(mapping[family].adjectives)}-${takeRandomFromArray(mapping[family].nouns)}`;
108
111
  }
112
+ /**
113
+ * Given a string, it returns it with the first letter capitalized.
114
+ *
115
+ * @param str - String to capitalize.
116
+ * @returns String with the first letter capitalized.
117
+ */
118
+ export function capitalize(str) {
119
+ return str.substring(0, 1).toUpperCase() + str.substring(1);
120
+ }
121
+ /**
122
+ * Try to convert a string to an int, falling back to undefined if unable to.
123
+ *
124
+ * @param maybeInt - String to convert to an int.
125
+ * @returns The int if it was able to convert, otherwise undefined.
126
+ */
127
+ export function tryParseInt(maybeInt) {
128
+ let asInt;
129
+ if (maybeInt !== undefined) {
130
+ asInt = parseInt(maybeInt, 10);
131
+ if (isNaN(asInt)) {
132
+ asInt = undefined;
133
+ }
134
+ }
135
+ return asInt;
136
+ }
137
+ /**
138
+ * Transforms a matrix of strings into a single string with the columns aligned.
139
+ *
140
+ * @param lines - Array of rows, where each row is an array of strings (representing columns).
141
+ * @returns A string with the columns aligned.
142
+ */
143
+ export function linesToColumns(lines) {
144
+ const widths = [];
145
+ for (let i = 0; lines[0] && i < lines[0].length; i++) {
146
+ const columnRows = lines.map((line) => line[i]);
147
+ widths.push(Math.max(...columnRows.map((row) => unstyled(row).length)));
148
+ }
149
+ const paddedLines = lines
150
+ .map((line) => {
151
+ return line
152
+ .map((col, index) => {
153
+ return `${col}${' '.repeat(widths[index] - unstyled(col).length)}`;
154
+ })
155
+ .join(' ')
156
+ .trimEnd();
157
+ })
158
+ .join('\n');
159
+ return paddedLines;
160
+ }
161
+ /**
162
+ * Given a string, it transforms it to a slug (lowercase, hyphenated, no special chars, trimmed...).
163
+ *
164
+ * @param str - String to slugify.
165
+ * @returns The slugified string.
166
+ */
167
+ export function slugify(str) {
168
+ return str
169
+ .toLowerCase()
170
+ .trim()
171
+ .replace(/[^\w\s-]/g, '')
172
+ .replace(/[\s_-]+/g, '-')
173
+ .replace(/^-+|-+$/g, '');
174
+ }
175
+ /**
176
+ * Given a string, it returns it with the special regex characters escaped.
177
+ * More info: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping.
178
+ *
179
+ * @param str - String to escape.
180
+ * @returns The escaped string.
181
+ */
182
+ export function escapeRegExp(str) {
183
+ return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
184
+ }
185
+ /**
186
+ * Transform a string to camelCase.
187
+ */
188
+ export { camelCase as camelize } from 'change-case';
189
+ /**
190
+ * Transform a string to param-case.
191
+ */
192
+ export { paramCase as hyphenate } from 'change-case';
193
+ /**
194
+ * Transform a string to snake_case.
195
+ */
196
+ export { snakeCase as underscore } from 'change-case';
197
+ /**
198
+ * Transform a string to CONSTANT_CASE.
199
+ */
200
+ export { constantCase as constantize } from 'change-case';
109
201
  //# sourceMappingURL=string.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"string.js","sourceRoot":"","sources":["../../../src/public/common/string.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC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AAK,EAAE,0BAA0B;SAClC;QACD,QAAQ,EAAE;YACR,UAAU,EAAE,+BAA+B;YAC3C,KAAK,EAAE,0BAA0B;SAClC;KACF,CAAA;IACD,OAAO,GAAG,mBAAmB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,UAAU,CAAC,IAAI,mBAAmB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,EAAE,CAAA;AAC3G,CAAC","sourcesContent":["import {takeRandomFromArray} from './array.js'\n\nconst SAFE_RANDOM_BUSINESS_ADJECTIVES = [\n 'commercial',\n 'profitable',\n 'amortizable',\n 'branded',\n 'integrated',\n 'synergistic',\n 'consolidated',\n 'diversified',\n 'lean',\n 'niche',\n 'premium',\n 'luxury',\n 'scalable',\n 'optimized',\n 'empowered',\n 'international',\n 'beneficial',\n 'fruitful',\n 'extensive',\n 'lucrative',\n 'modern',\n]\n\nconst SAFE_RANDOM_CREATIVE_ADJECTIVES = [\n 'bright',\n 'impactful',\n 'stylish',\n 'colorful',\n 'modern',\n 'minimal',\n 'trendy',\n 'creative',\n 'artistic',\n 'spectacular',\n 'glamorous',\n 'luxury',\n 'retro',\n 'nostalgic',\n 'comfy',\n 'polished',\n 'fabulous',\n 'balanced',\n 'monochrome',\n 'glitched',\n]\n\nconst SAFE_RANDOM_BUSINESS_NOUNS = [\n 'account',\n 'consumer',\n 'customer',\n 'enterprise',\n 'business',\n 'venture',\n 'marketplace',\n 'revenue',\n 'vertical',\n 'portfolio',\n 'negotiation',\n 'shipping',\n 'demand',\n 'supply',\n 'growth',\n 'merchant',\n 'investment',\n 'shareholder',\n 'conversion',\n 'capital',\n 'projection',\n 'upside',\n 'trade',\n 'deal',\n 'merchandise',\n 'transaction',\n 'sale',\n]\n\nconst SAFE_RANDOM_CREATIVE_NOUNS = [\n 'vibe',\n 'style',\n 'moment',\n 'mood',\n 'flavor',\n 'look',\n 'appearance',\n 'perspective',\n 'aspect',\n 'ambience',\n 'quality',\n 'backdrop',\n 'focus',\n 'tone',\n]\n\nexport type RandomNameFamily = 'business' | 'creative'\n\n/**\n * @param family - Theme to use for the random name\n * @returns A random name generated by combining an adjective and noun.\n */\nexport function getRandomName(family: RandomNameFamily = 'business'): string {\n const mapping = {\n business: {\n adjectives: SAFE_RANDOM_BUSINESS_ADJECTIVES,\n nouns: SAFE_RANDOM_BUSINESS_NOUNS,\n },\n creative: {\n adjectives: SAFE_RANDOM_CREATIVE_ADJECTIVES,\n nouns: SAFE_RANDOM_CREATIVE_NOUNS,\n },\n }\n return `${takeRandomFromArray(mapping[family].adjectives)}-${takeRandomFromArray(mapping[family].nouns)}`\n}\n"]}
1
+ {"version":3,"file":"string.js","sourceRoot":"","sources":["../../../src/public/common/string.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,mBAAmB,EAAC,MAAM,YAAY,CAAA;AAC9C,OAAO,EAAC,QAAQ,EAAC,MAAM,iBAAiB,CAAA;AAExC,MAAM,+BAA+B,GAAG;IACtC,YAAY;IACZ,YAAY;IACZ,aAAa;IACb,SAAS;IACT,YAAY;IACZ,aAAa;IACb,cAAc;IACd,aAAa;IACb,MAAM;IACN,OAAO;IACP,SAAS;IACT,QAAQ;IACR,UAAU;IACV,WAAW;IACX,WAAW;IACX,eAAe;IACf,YAAY;IACZ,UAAU;IACV,WAAW;IACX,WAAW;IACX,QAAQ;CACT,CAAA;AAED,MAAM,+BAA+B,GAAG;IACtC,QAAQ;IACR,WAAW;IACX,SAAS;IACT,UAAU;IACV,QAAQ;IACR,SAAS;IACT,QAAQ;IACR,UAAU;IACV,UAAU;IACV,aAAa;IACb,WAAW;IACX,QAAQ;IACR,OAAO;IACP,WAAW;IACX,OAAO;IACP,UAAU;IACV,UAAU;IACV,UAAU;IACV,YAAY;IACZ,UAAU;CACX,CAAA;AAED,MAAM,0BAA0B,GAAG;IACjC,SAAS;IACT,UAAU;IACV,UAAU;IACV,YAAY;IACZ,UAAU;IACV,SAAS;IACT,aAAa;IACb,SAAS;IACT,UAAU;IACV,WA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AC,UAAU,EAAE,EAAE,CAAC,CAAA;AAC5B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,GAAW;IACtC,OAAO,GAAG,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAA;AACnD,CAAC;AAED;;GAEG;AACH,OAAO,EAAC,SAAS,IAAI,QAAQ,EAAC,MAAM,aAAa,CAAA;AAEjD;;GAEG;AACH,OAAO,EAAC,SAAS,IAAI,SAAS,EAAC,MAAM,aAAa,CAAA;AAElD;;GAEG;AACH,OAAO,EAAC,SAAS,IAAI,UAAU,EAAC,MAAM,aAAa,CAAA;AAEnD;;GAEG;AACH,OAAO,EAAC,YAAY,IAAI,WAAW,EAAC,MAAM,aAAa,CAAA","sourcesContent":["import {takeRandomFromArray} from './array.js'\nimport {unstyled} from '../../output.js'\n\nconst SAFE_RANDOM_BUSINESS_ADJECTIVES = [\n 'commercial',\n 'profitable',\n 'amortizable',\n 'branded',\n 'integrated',\n 'synergistic',\n 'consolidated',\n 'diversified',\n 'lean',\n 'niche',\n 'premium',\n 'luxury',\n 'scalable',\n 'optimized',\n 'empowered',\n 'international',\n 'beneficial',\n 'fruitful',\n 'extensive',\n 'lucrative',\n 'modern',\n]\n\nconst SAFE_RANDOM_CREATIVE_ADJECTIVES = [\n 'bright',\n 'impactful',\n 'stylish',\n 'colorful',\n 'modern',\n 'minimal',\n 'trendy',\n 'creative',\n 'artistic',\n 'spectacular',\n 'glamorous',\n 'luxury',\n 'retro',\n 'nostalgic',\n 'comfy',\n 'polished',\n 'fabulous',\n 'balanced',\n 'monochrome',\n 'glitched',\n]\n\nconst SAFE_RANDOM_BUSINESS_NOUNS = [\n 'account',\n 'consumer',\n 'customer',\n 'enterprise',\n 'business',\n 'venture',\n 'marketplace',\n 'revenue',\n 'vertical',\n 'portfolio',\n 'negotiation',\n 'shipping',\n 'demand',\n 'supply',\n 'growth',\n 'merchant',\n 'investment',\n 'shareholder',\n 'conversion',\n 'capital',\n 'projection',\n 'upside',\n 'trade',\n 'deal',\n 'merchandise',\n 'transaction',\n 'sale',\n]\n\nconst SAFE_RANDOM_CREATIVE_NOUNS = [\n 'vibe',\n 'style',\n 'moment',\n 'mood',\n 'flavor',\n 'look',\n 'appearance',\n 'perspective',\n 'aspect',\n 'ambience',\n 'quality',\n 'backdrop',\n 'focus',\n 'tone',\n]\n\nexport type RandomNameFamily = 'business' | 'creative'\n\n/**\n * Generates a random name by combining an adjective and noun.\n *\n * @param family - Theme to use for the random name (business or creative).\n * @returns A random name generated by combining an adjective and noun.\n */\nexport function getRandomName(family: RandomNameFamily = 'business'): string {\n const mapping = {\n business: {\n adjectives: SAFE_RANDOM_BUSINESS_ADJECTIVES,\n nouns: SAFE_RANDOM_BUSINESS_NOUNS,\n },\n creative: {\n adjectives: SAFE_RANDOM_CREATIVE_ADJECTIVES,\n nouns: SAFE_RANDOM_CREATIVE_NOUNS,\n },\n }\n return `${takeRandomFromArray(mapping[family].adjectives)}-${takeRandomFromArray(mapping[family].nouns)}`\n}\n\n/**\n * Given a string, it returns it with the first letter capitalized.\n *\n * @param str - String to capitalize.\n * @returns String with the first letter capitalized.\n */\nexport function capitalize(str: string): string {\n return str.substring(0, 1).toUpperCase() + str.substring(1)\n}\n\n/**\n * Try to convert a string to an int, falling back to undefined if unable to.\n *\n * @param maybeInt - String to convert to an int.\n * @returns The int if it was able to convert, otherwise undefined.\n */\nexport function tryParseInt(maybeInt: string | undefined): number | undefined {\n let asInt: number | undefined\n if (maybeInt !== undefined) {\n asInt = parseInt(maybeInt, 10)\n if (isNaN(asInt)) {\n asInt = undefined\n }\n }\n return asInt\n}\n\n/**\n * Transforms a matrix of strings into a single string with the columns aligned.\n *\n * @param lines - Array of rows, where each row is an array of strings (representing columns).\n * @returns A string with the columns aligned.\n */\nexport function linesToColumns(lines: string[][]): string {\n const widths: number[] = []\n for (let i = 0; lines[0] && i < lines[0].length; i++) {\n const columnRows = lines.map((line) => line[i]!)\n widths.push(Math.max(...columnRows.map((row) => unstyled(row).length)))\n }\n const paddedLines = lines\n .map((line) => {\n return line\n .map((col, index) => {\n return `${col}${' '.repeat(widths[index]! - unstyled(col).length)}`\n })\n .join(' ')\n .trimEnd()\n })\n .join('\\n')\n return paddedLines\n}\n\n/**\n * Given a string, it transforms it to a slug (lowercase, hyphenated, no special chars, trimmed...).\n *\n * @param str - String to slugify.\n * @returns The slugified string.\n */\nexport function slugify(str: string): string {\n return str\n .toLowerCase()\n .trim()\n .replace(/[^\\w\\s-]/g, '')\n .replace(/[\\s_-]+/g, '-')\n .replace(/^-+|-+$/g, '')\n}\n\n/**\n * Given a string, it returns it with the special regex characters escaped.\n * More info: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping.\n *\n * @param str - String to escape.\n * @returns The escaped string.\n */\nexport function escapeRegExp(str: string): string {\n return str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n}\n\n/**\n * Transform a string to camelCase.\n */\nexport {camelCase as camelize} from 'change-case'\n\n/**\n * Transform a string to param-case.\n */\nexport {paramCase as hyphenate} from 'change-case'\n\n/**\n * Transform a string to snake_case.\n */\nexport {snakeCase as underscore} from 'change-case'\n\n/**\n * Transform a string to CONSTANT_CASE.\n */\nexport {constantCase as constantize} from 'change-case'\n"]}
@@ -0,0 +1,11 @@
1
+ import { AdminSession } from '../../../session.js';
2
+ import { GraphQLVariables } from '../../../private/node/api/graphql.js';
3
+ /**
4
+ * Executes a GraphQL query against the Admin API.
5
+ *
6
+ * @param query - GraphQL query to execute.
7
+ * @param session - Shopify admin session including token and Store FQDN.
8
+ * @param variables - GraphQL variables to pass to the query.
9
+ * @returns The response of the query of generic type <T>.
10
+ */
11
+ export declare function adminRequest<T>(query: string, session: AdminSession, variables?: GraphQLVariables): Promise<T>;
@@ -0,0 +1,70 @@
1
+ import { content, token as outputToken } from '../../../output.js';
2
+ import { Bug, Abort } from '../../../error.js';
3
+ import { graphqlRequest } from '../../../private/node/api/graphql.js';
4
+ import { ClientError, gql } from 'graphql-request';
5
+ /**
6
+ * Executes a GraphQL query against the Admin API.
7
+ *
8
+ * @param query - GraphQL query to execute.
9
+ * @param session - Shopify admin session including token and Store FQDN.
10
+ * @param variables - GraphQL variables to pass to the query.
11
+ * @returns The response of the query of generic type <T>.
12
+ */
13
+ export async function adminRequest(query, session, variables) {
14
+ const api = 'Admin';
15
+ const version = await fetchApiVersion(session);
16
+ const url = adminUrl(session.storeFqdn, version);
17
+ return graphqlRequest(query, api, url, session.token, variables);
18
+ }
19
+ /**
20
+ * GraphQL query to retrieve the latest supported API version.
21
+ *
22
+ * @param session - Shopify admin session including token and Store FQDN.
23
+ * @returns - The latest supported API version.
24
+ */
25
+ async function fetchApiVersion(session) {
26
+ const url = adminUrl(session.storeFqdn, 'unstable');
27
+ const query = apiVersionQuery();
28
+ try {
29
+ const data = await graphqlRequest(query, 'Admin', url, session.token, {}, false);
30
+ return data.publicApiVersions
31
+ .filter((item) => item.supported)
32
+ .map((item) => item.handle)
33
+ .sort()
34
+ .reverse()[0];
35
+ }
36
+ catch (error) {
37
+ if (error instanceof ClientError && error.response.status === 403) {
38
+ const storeName = session.storeFqdn.replace('.myshopify.com', '');
39
+ throw new Abort(content `Looks like you don't have access this dev store: (${outputToken.link(storeName, `https://${session.storeFqdn}`)})`, content `If you're not the owner, create a dev store staff account for yourself`);
40
+ }
41
+ throw new Bug(`Unknown error connecting to your store`);
42
+ }
43
+ }
44
+ /**
45
+ * Returns the Admin API URL for the given store and version.
46
+ *
47
+ * @param store - Store FQDN.
48
+ * @param version - API version.
49
+ * @returns - Admin API URL.
50
+ */
51
+ function adminUrl(store, version) {
52
+ const realVersion = version || 'unstable';
53
+ return `https://${store}/admin/api/${realVersion}/graphql.json`;
54
+ }
55
+ /**
56
+ * GraphQL query string to retrieve the latest supported API version.
57
+ *
58
+ * @returns - A query string.
59
+ */
60
+ function apiVersionQuery() {
61
+ return gql `
62
+ query {
63
+ publicApiVersions {
64
+ handle
65
+ supported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AC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC;aAC1B,IAAI,EAAE;aACN,OAAO,EAAE,CAAC,CAAC,CAAE,CAAA;KACjB;IAAC,OAAO,KAAK,EAAE;QACd,IAAI,KAAK,YAAY,WAAW,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE;YACjE,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAA;YACjE,MAAM,IAAI,KAAK,CACb,OAAO,CAAA,qDAAqD,WAAW,CAAC,IAAI,CAC1E,SAAS,EACT,WAAW,OAAO,CAAC,SAAS,EAAE,CAC/B,GAAG,EACJ,OAAO,CAAA,wEAAwE,CAChF,CAAA;SACF;QACD,MAAM,IAAI,GAAG,CAAC,wCAAwC,CAAC,CAAA;KACxD;AACH,CAAC;AAED;;;;;;GAMG;AACH,SAAS,QAAQ,CAAC,KAAa,EAAE,OAA2B;IAC1D,MAAM,WAAW,GAAG,OAAO,IAAI,UAAU,CAAA;IACzC,OAAO,WAAW,KAAK,cAAc,WAAW,eAAe,CAAA;AACjE,CAAC;AAMD;;;;GAIG;AACH,SAAS,eAAe;IACtB,OAAO,GAAG,CAAA;;;;;;;GAOT,CAAA;AACH,CAAC","sourcesContent":["import {AdminSession} from '../../../session.js'\nimport {content, token as outputToken} from '../../../output.js'\nimport {Bug, Abort} from '../../../error.js'\nimport {graphqlRequest, GraphQLVariables} from '../../../private/node/api/graphql.js'\nimport {ClientError, gql} from 'graphql-request'\n\n/**\n * Executes a GraphQL query against the Admin API.\n *\n * @param query - GraphQL query to execute.\n * @param session - Shopify admin session including token and Store FQDN.\n * @param variables - GraphQL variables to pass to the query.\n * @returns The response of the query of generic type <T>.\n */\nexport async function adminRequest<T>(query: string, session: AdminSession, variables?: GraphQLVariables): Promise<T> {\n const api = 'Admin'\n const version = await fetchApiVersion(session)\n const url = adminUrl(session.storeFqdn, version)\n return graphqlRequest(query, api, url, session.token, variables)\n}\n\n/**\n * GraphQL query to retrieve the latest supported API version.\n *\n * @param session - Shopify admin session including token and Store FQDN.\n * @returns - The latest supported API version.\n */\nasync function fetchApiVersion(session: AdminSession): Promise<string> {\n const url = adminUrl(session.storeFqdn, 'unstable')\n const query = apiVersionQuery()\n try {\n const data: ApiVersionResponse = await graphqlRequest(query, 'Admin', url, session.token, {}, false)\n\n return data.publicApiVersions\n .filter((item) => item.supported)\n .map((item) => item.handle)\n .sort()\n .reverse()[0]!\n } catch (error) {\n if (error instanceof ClientError && error.response.status === 403) {\n const storeName = session.storeFqdn.replace('.myshopify.com', '')\n throw new Abort(\n content`Looks like you don't have access this dev store: (${outputToken.link(\n storeName,\n `https://${session.storeFqdn}`,\n )})`,\n content`If you're not the owner, create a dev store staff account for yourself`,\n )\n }\n throw new Bug(`Unknown error connecting to your store`)\n }\n}\n\n/**\n * Returns the Admin API URL for the given store and version.\n *\n * @param store - Store FQDN.\n * @param version - API version.\n * @returns - Admin API URL.\n */\nfunction adminUrl(store: string, version: string | undefined): string {\n const realVersion = version || 'unstable'\n return `https://${store}/admin/api/${realVersion}/graphql.json`\n}\n\ninterface ApiVersionResponse {\n publicApiVersions: {handle: string; supported: boolean}[]\n}\n\n/**\n * GraphQL query string to retrieve the latest supported API version.\n *\n * @returns - A query string.\n */\nfunction apiVersionQuery(): string {\n return gql`\n query {\n publicApiVersions {\n handle\n supported\n }\n }\n `\n}\n"]}
@@ -0,0 +1,22 @@
1
+ import { GraphQLVariables } from '../../../private/node/api/graphql.js';
2
+ import FormData from 'form-data';
3
+ import { Response } from 'node-fetch';
4
+ /**
5
+ * Executes a GraphQL query against the Oxygen API.
6
+ *
7
+ * @param oxygenAddress - Oxygen address to query.
8
+ * @param query - GraphQL query to execute.
9
+ * @param token - Shopify access token.
10
+ * @param variables - GraphQL variables to pass to the query.
11
+ * @returns The response of the query of generic type <T>.
12
+ */
13
+ export declare function oxygenRequest<T>(oxygenAddress: string, query: string, token: string, variables?: GraphQLVariables): Promise<T>;
14
+ /**
15
+ * Uploads a deployment file to the Oxygen API.
16
+ *
17
+ * @param oxygenAddress - Oxygen address to upload to.
18
+ * @param token - Shopify access token.
19
+ * @param data - FormData to upload.
20
+ * @returns The response of the query.
21
+ */
22
+ export declare function uploadOxygenDeploymentFile(oxygenAddress: string, token: string, data: FormData): Promise<Response>;
@@ -0,0 +1,40 @@
1
+ import { shopifyFetch } from '../../../http.js';
2
+ import { graphqlRequest } from '../../../private/node/api/graphql.js';
3
+ import { buildHeaders } from '../../../private/node/api/headers.js';
4
+ /**
5
+ * Executes a GraphQL query against the Oxygen API.
6
+ *
7
+ * @param oxygenAddress - Oxygen address to query.
8
+ * @param query - GraphQL query to execute.
9
+ * @param token - Shopify access token.
10
+ * @param variables - GraphQL variables to pass to the query.
11
+ * @returns The response of the query of generic type <T>.
12
+ */
13
+ export async function oxygenRequest(oxygenAddress, query, token, variables) {
14
+ return graphqlRequest(query, 'Oxygen', getOxygenAddress(oxygenAddress), token, variables);
15
+ }
16
+ /**
17
+ * Uploads a deployment file to the Oxygen API.
18
+ *
19
+ * @param oxygenAddress - Oxygen address to upload to.
20
+ * @param token - Shopify access token.
21
+ * @param data - FormData to upload.
22
+ * @returns The response of the query.
23
+ */
24
+ export async function uploadOxygenDeploymentFile(oxygenAddress, token, data) {
25
+ const headers = await buildHeaders(token);
26
+ delete headers['Content-Type'];
27
+ const response = await shopifyFetch(getOxygenAddress(oxygenAddress), {
28
+ method: 'POST',
29
+ body: data,
30
+ headers: {
31
+ ...headers,
32
+ ...data.getHeaders(),
33
+ },
34
+ });
35
+ return response;
36
+ }
37
+ const getOxygenAddress = (oxygenHost) => {
38
+ return `https://${oxygenHost}/api/graphql/deploy/v1`;
39
+ };
40
+ //# sourceMappingURL=oxygen.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oxygen.js","sourceRoot":"","sources":["../../../../src/public/node/api/oxygen.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAC,cAAc,EAAmB,MAAM,sCAAsC,CAAA;AACrF,OAAO,EAAC,YAAY,EAAC,MAAM,sCAAsC,CAAA;AAIjE;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,aAAqB,EACrB,KAAa,EACb,KAAa,EACb,SAA4B;IAE5B,OAAO,cAAc,CAAC,KAAK,EAAE,QAAQ,EAAE,gBAAgB,CAAC,aAAa,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,CAAA;AAC3F,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,aAAqB,EACrB,KAAa,EACb,IAAc;IAEd,MAAM,OAAO,GAAG,MAAM,YAAY,CAAC,KAAK,CAAC,CAAA;IACzC,OAAO,OAAO,CAAC,cAAc,CAAC,CAAA;IAE9B,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,gBAAgB,CAAC,aAAa,CAAC,EAAE;QACnE,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,IAAI;QACV,OAAO,EAAE;YACP,GAAG,OAAO;YACV,GAAG,IAAI,CAAC,UAAU,EAAE;SACrB;KACF,CAAC,CAAA;IAEF,OAAO,QAAQ,CAAA;AACjB,CAAC;AAED,MAAM,gBAAgB,GAAG,CAAC,UAAkB,EAAU,EAAE;IACtD,OAAO,WAAW,UAAU,wBAAwB,CAAA;AACtD,CAAC,CAAA","sourcesContent":["import {shopifyFetch} from '../../../http.js'\nimport {graphqlRequest, GraphQLVariables} from '../../../private/node/api/graphql.js'\nimport {buildHeaders} from '../../../private/node/api/headers.js'\nimport FormData from 'form-data'\nimport {Response} from 'node-fetch'\n\n/**\n * Executes a GraphQL query against the Oxygen API.\n *\n * @param oxygenAddress - Oxygen address to query.\n * @param query - GraphQL query to execute.\n * @param token - Shopify access token.\n * @param variables - GraphQL variables to pass to the query.\n * @returns The response of the query of generic type <T>.\n */\nexport async function oxygenRequest<T>(\n oxygenAddress: string,\n query: string,\n token: string,\n variables?: GraphQLVariables,\n): Promise<T> {\n return graphqlRequest(query, 'Oxygen', getOxygenAddress(oxygenAddress), token, variables)\n}\n\n/**\n * Uploads a deployment file to the Oxygen API.\n *\n * @param oxygenAddress - Oxygen address to upload to.\n * @param token - Shopify access token.\n * @param data - FormData to upload.\n * @returns The response of the query.\n */\nexport async function uploadOxygenDeploymentFile(\n oxygenAddress: string,\n token: string,\n data: FormData,\n): Promise<Response> {\n const headers = await buildHeaders(token)\n delete headers['Content-Type']\n\n const response = await shopifyFetch(getOxygenAddress(oxygenAddress), {\n method: 'POST',\n body: data,\n headers: {\n ...headers,\n ...data.getHeaders(),\n },\n })\n\n return response\n}\n\nconst getOxygenAddress = (oxygenHost: string): string => {\n return `https://${oxygenHost}/api/graphql/deploy/v1`\n}\n"]}
@@ -1,5 +1,13 @@
1
- import { Variables, RequestDocument } from 'graphql-request';
2
- export declare function request<T>(query: RequestDocument, token: string, variables?: Variables): Promise<T>;
1
+ import { GraphQLVariables } from '../../../private/node/api/graphql.js';
2
+ /**
3
+ * Executes a GraphQL query against the Partners API.
4
+ *
5
+ * @param query - GraphQL query to execute.
6
+ * @param token - Partners token.
7
+ * @param variables - GraphQL variables to pass to the query.
8
+ * @returns The response of the query of generic type <T>.
9
+ */
10
+ export declare function partnersRequest<T>(query: string, token: string, variables?: GraphQLVariables): Promise<T>;
3
11
  /**
4
12
  * Function queries are proxied through the script service proxy.
5
13
  * To execute a query, we encapsulate it inside another query (including the variables)
@@ -7,7 +15,7 @@ export declare function request<T>(query: RequestDocument, token: string, variab
7
15
  *
8
16
  * @param apiKey - APIKey of the app where the query will be executed.
9
17
  * @param query - GraphQL query to execute.
10
- * @param token - Partners token
18
+ * @param token - Partners token.
11
19
  * @param variables - GraphQL variables to pass to the query.
12
20
  * @returns The response of the query.
13
21
  */
@@ -0,0 +1,40 @@
1
+ import { partners as partnersFqdn } from '../../../environment/fqdn.js';
2
+ import { graphqlRequest } from '../../../private/node/api/graphql.js';
3
+ import { ScriptServiceProxyQuery } from '../../../api/graphql/index.js';
4
+ /**
5
+ * Executes a GraphQL query against the Partners API.
6
+ *
7
+ * @param query - GraphQL query to execute.
8
+ * @param token - Partners token.
9
+ * @param variables - GraphQL variables to pass to the query.
10
+ * @returns The response of the query of generic type <T>.
11
+ */
12
+ export async function partnersRequest(query, token, variables) {
13
+ const api = 'Partners';
14
+ const fqdn = await partnersFqdn();
15
+ const url = `https://${fqdn}/api/cli/graphql`;
16
+ return graphqlRequest(query, api, url, token, variables);
17
+ }
18
+ /**
19
+ * Function queries are proxied through the script service proxy.
20
+ * To execute a query, we encapsulate it inside another query (including the variables)
21
+ * This is done automatically, you just need to provide the query and the variables.
22
+ *
23
+ * @param apiKey - APIKey of the app where the query will be executed.
24
+ * @param query - GraphQL query to execute.
25
+ * @param token - Partners token.
26
+ * @param variables - GraphQL variables to pass to the query.
27
+ * @returns The response of the query.
28
+ */
29
+ export async function functionProxyRequest(apiKey, query, token, variables) {
30
+ const proxyVariables = {
31
+ api_key: apiKey,
32
+ query,
33
+ variables: JSON.stringify(variables) || '{}',
34
+ };
35
+ const proxyQuery = ScriptServiceProxyQuery;
36
+ const res = await partnersRequest(proxyQuery, token, proxyVariables);
37
+ const json = JSON.parse(res.scriptServiceProxy);
38
+ return json;
39
+ }
40
+ //# sourceMappingURL=partners.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"partners.js","sourceRoot":"","sources":["../../../../src/public/node/api/partners.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,IAAI,YAAY,EAAC,MAAM,8BAA8B,CAAA;AACrE,OAAO,EAAC,cAAc,EAAmB,MAAM,sCAAsC,CAAA;AACrF,OAAO,EAAC,uBAAuB,EAAC,MAAM,+BAA+B,CAAA;AAErE;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAI,KAAa,EAAE,KAAa,EAAE,SAA4B;IACjG,MAAM,GAAG,GAAG,UAAU,CAAA;IACtB,MAAM,IAAI,GAAG,MAAM,YAAY,EAAE,CAAA;IACjC,MAAM,GAAG,GAAG,WAAW,IAAI,kBAAkB,CAAA;IAC7C,OAAO,cAAc,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,SAAS,CAAC,CAAA;AAC1D,CAAC;AAMD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,MAAc,EACd,KAAc,EACd,KAAa,EACb,SAAmB;IAEnB,MAAM,cAAc,GAAG;QACrB,OAAO,EAAE,MAAM;QACf,KAAK;QACL,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,IAAI;KAC7C,CAAA;IACD,MAAM,UAAU,GAAG,uBAAuB,CAAA;IAC1C,MAAM,GAAG,GAAkB,MAAM,eAAe,CAAC,UAAU,EAAE,KAAK,EAAE,cAAc,CAAC,CAAA;IACnF,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAA;IAC/C,OAAO,IAAS,CAAA;AAClB,CAAC","sourcesContent":["import {partners as partnersFqdn} from '../../../environment/fqdn.js'\nimport {graphqlRequest, GraphQLVariables} from '../../../private/node/api/graphql.js'\nimport {ScriptServiceProxyQuery} from '../../../api/graphql/index.js'\n\n/**\n * Executes a GraphQL query against the Partners API.\n *\n * @param query - GraphQL query to execute.\n * @param token - Partners token.\n * @param variables - GraphQL variables to pass to the query.\n * @returns The response of the query of generic type <T>.\n */\nexport async function partnersRequest<T>(query: string, token: string, variables?: GraphQLVariables): Promise<T> {\n const api = 'Partners'\n const fqdn = await partnersFqdn()\n const url = `https://${fqdn}/api/cli/graphql`\n return graphqlRequest(query, api, url, token, variables)\n}\n\ninterface ProxyResponse {\n scriptServiceProxy: string\n}\n\n/**\n * Function queries are proxied through the script service proxy.\n * To execute a query, we encapsulate it inside another query (including the variables)\n * This is done automatically, you just need to provide the query and the variables.\n *\n * @param apiKey - APIKey of the app where the query will be executed.\n * @param query - GraphQL query to execute.\n * @param token - Partners token.\n * @param variables - GraphQL variables to pass to the query.\n * @returns The response of the query.\n */\nexport async function functionProxyRequest<T>(\n apiKey: string,\n query: unknown,\n token: string,\n variables?: unknown,\n): Promise<T> {\n const proxyVariables = {\n api_key: apiKey,\n query,\n variables: JSON.stringify(variables) || '{}',\n }\n const proxyQuery = ScriptServiceProxyQuery\n const res: ProxyResponse = await partnersRequest(proxyQuery, token, proxyVariables)\n const json = JSON.parse(res.scriptServiceProxy)\n return json as T\n}\n"]}
@@ -4,7 +4,7 @@ import { isDevelopment } from '../../environment/local.js';
4
4
  import { Abort } from '../../error.js';
5
5
  import { addPublic } from '../../metadata.js';
6
6
  import { content, info, token } from '../../output.js';
7
- import { hashString } from '../../string.js';
7
+ import { hashString } from '../../public/node/crypto.js';
8
8
  import { isTruthy } from '../../environment/utilities.js';
9
9
  import { Command } from '@oclif/core';
10
10
  class BaseCommand extends Command {
@@ -1 +1 @@
1
- {"version":3,"file":"base-command.js","sourceRoot":"","sources":["../../../src/public/node/base-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAE,2CAA2C,EAAC,MAAM,oBAAoB,CAAA;AAC5F,OAAO,EAAC,wBAAwB,EAAC,MAAM,cAAc,CAAA;AAErD,OAAO,EAAC,aAAa,EAAC,MAAM,4BAA4B,CAAA;AACxD,OAAO,EAAC,KAAK,EAAC,MAAM,gBAAgB,CAAA;AACpC,OAAO,EAAC,SAAS,EAAC,MAAM,mBAAmB,CAAA;AAC3C,OAAO,EAAC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAC,MAAM,iBAAiB,CAAA;AACpD,OAAO,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAA;AAC1C,OAAO,EAAC,QAAQ,EAAC,MAAM,gCAAgC,CAAA;AACvD,OAAO,EAAC,OAAO,EAAa,MAAM,aAAa,CAAA;AAO/C,MAAe,WAAY,SAAQ,OAA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AAE,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC,CAAA;aAClE;iBAAM;gBACL,IAAI,CAAC,IAAI,CAAC,KAAK,KAAK,EAAE,EAAE,GAAG,KAAK,EAAE,CAAC,CAAA;aACpC;SACF;KACF;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAED,eAAe,WAAW,CAAA","sourcesContent":["import {errorHandler, registerCleanBugsnagErrorsFromWithinPlugins} from './error-handler.js'\nimport {loadPresetsFromDirectory} from './presets.js'\nimport {JsonMap} from '../../private/common/json.js'\nimport {isDevelopment} from '../../environment/local.js'\nimport {Abort} from '../../error.js'\nimport {addPublic} from '../../metadata.js'\nimport {content, info, token} from '../../output.js'\nimport {hashString} from '../../string.js'\nimport {isTruthy} from '../../environment/utilities.js'\nimport {Command, Interfaces} from '@oclif/core'\n\ninterface PresettableFlags {\n preset?: string\n path?: string\n}\n\nabstract class BaseCommand extends Command {\n public static analyticsNameOverride(): string | undefined {\n return undefined\n }\n\n async catch(error: Error & {exitCode?: number | undefined}): Promise<void> {\n await errorHandler(error, this.config)\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n protected async init(): Promise<any> {\n this.exitWithTimestampWhenEnvVariablePresent()\n if (!isDevelopment()) {\n // This function runs just prior to `run`\n await registerCleanBugsnagErrorsFromWithinPlugins(this.config)\n }\n return super.init()\n }\n\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\n protected exitWithTimestampWhenEnvVariablePresent() {\n if (isTruthy(process.env.SHOPIFY_CLI_ENV_STARTUP_PERFORMANCE_RUN)) {\n info(`\n SHOPIFY_CLI_TIMESTAMP_START\n { \"timestamp\": ${Date.now()} }\n SHOPIFY_CLI_TIMESTAMP_END\n `)\n process.exit(0)\n }\n }\n\n protected async parse<\n TFlags extends Interfaces.FlagOutput & {path?: string; verbose?: boolean},\n TGlobalFlags extends Interfaces.FlagOutput,\n TArgs extends Interfaces.OutputArgs,\n >(\n options?: Interfaces.Input<TFlags, TGlobalFlags>,\n argv?: string[],\n ): Promise<Interfaces.ParserOutput<TFlags, TGlobalFlags, TArgs>> {\n let result = await super.parse<TFlags, TGlobalFlags, TArgs>(options, argv)\n result = await this.resultWithPreset<TFlags, TGlobalFlags, TArgs>(result, options, argv)\n await addFromParsedFlags(result.flags)\n return result\n }\n\n protected async resultWithPreset<\n TFlags extends Interfaces.FlagOutput & {path?: string; verbose?: boolean},\n TGlobalFlags extends Interfaces.FlagOutput,\n TArgs extends Interfaces.OutputArgs,\n >(\n originalResult: Interfaces.ParserOutput<TFlags, TGlobalFlags, TArgs>,\n options?: Interfaces.Input<TFlags, TGlobalFlags>,\n argv?: string[],\n ): Promise<Interfaces.ParserOutput<TFlags, TGlobalFlags, TArgs>> {\n // If no preset is specified, don't modify the results\n const flags = originalResult.flags as PresettableFlags\n if (!flags.preset) return originalResult\n\n // If the specified preset isn't found, don't modify the results\n const presets = await loadPresetsFromDirectory(await this.presetsPath(flags), {findUp: this.findUpForPresets()})\n const preset = presets[flags.preset]\n if (!preset) return originalResult\n\n // Parse using noDefaultsOptions to derive a list of flags specified as\n // command-line arguments.\n const noDefaultsResult = await super.parse<TFlags, TGlobalFlags, TArgs>(noDefaultsOptions(options), argv)\n\n // Add the preset's settings to argv and pass them to `super.parse`. This\n // invokes oclif's validation system without breaking the oclif black box.\n // Replace the original result with this one.\n const result = await super.parse<TFlags, TGlobalFlags, TArgs>(options, [\n // Need to specify argv default because we're merging with argsFromPreset.\n ...(argv || this.argv),\n ...argsFromPreset<TFlags, TGlobalFlags, TArgs>(preset, options, noDefaultsResult),\n ])\n\n // Report successful application of the preset.\n reportPresetApplication<TFlags, TGlobalFlags, TArgs>(noDefaultsResult.flags, result.flags, flags.preset, preset)\n\n return result\n }\n\n protected async presetsPath(rawFlags: {path?: string}): Promise<string> {\n return rawFlags.path || process.cwd()\n }\n\n protected findUpForPresets(): boolean {\n return true\n }\n}\n\nexport async function addFromParsedFlags(flags: {path?: string; verbose?: boolean}): Promise<void> {\n await addPublic(() => ({\n cmd_all_verbose: flags.verbose,\n cmd_all_path_override: flags.path !== undefined,\n cmd_all_path_override_hash: flags.path === undefined ? undefined : hashString(flags.path),\n }))\n}\n\n/**\n * Any flag which is:\n *\n * 1. Present in the final set of flags\n * 2. Specified in the preset\n * 3. Not specified by the user as a command line argument\n *\n * should be reported.\n *\n * It doesn't matter if the preset flag's value was the same as the default; from\n * the user's perspective, they want to know their preset was applied.\n */\nfunction reportPresetApplication<\n TFlags extends Interfaces.FlagOutput,\n TGlobalFlags extends Interfaces.FlagOutput,\n TArgs extends Interfaces.OutputArgs,\n>(\n noDefaultsFlags: Interfaces.ParserOutput<TFlags, TGlobalFlags, TArgs>['flags'],\n flagsWithPresets: Interfaces.ParserOutput<TFlags, TGlobalFlags, TArgs>['flags'],\n presetName: string,\n preset: JsonMap,\n): void {\n const changes: JsonMap = {}\n for (const [name, value] of Object.entries(flagsWithPresets)) {\n const userSpecifiedThisFlag = Object.prototype.hasOwnProperty.call(noDefaultsFlags, name)\n const presetContainsFlag = Object.prototype.hasOwnProperty.call(preset, name)\n if (!userSpecifiedThisFlag && presetContainsFlag) changes[name] = value\n }\n if (Object.keys(changes).length === 0) return\n info(content`Using applicable flags from the preset ${token.yellow(presetName)}:\n\n${Object.entries(changes)\n .map(([name, value]) => `• ${name} = ${value}`)\n .join('\\n')}\\n`)\n}\n\n/**\n * Strips the defaults from configured flags. For example, if flags contains:\n *\n * ```\n * someFlag: Flags.boolean({\n * description: 'some flag',\n * default: false\n * })\n * ```\n *\n * it becomes:\n *\n * ```\n * someFlag: Flags.boolean({\n * description: 'some flag'\n * })\n * ```\n *\n * If we parse using this configuration, the only specified flags will be those\n * the user actually passed on the command line.\n */\n\nfunction noDefaultsOptions<TFlags extends Interfaces.FlagOutput, TGlobalFlags extends Interfaces.FlagOutput>(\n options: Interfaces.Input<TFlags, TGlobalFlags> | undefined,\n): Interfaces.Input<TFlags, TGlobalFlags> | undefined {\n if (!options?.flags) return options\n return {\n ...options,\n flags: Object.fromEntries(\n Object.entries(options.flags).map(([label, settings]) => {\n const copiedSettings = {...(settings as {default?: unknown})}\n delete copiedSettings.default\n return [label, copiedSettings]\n }),\n ) as Interfaces.FlagInput<TFlags>,\n }\n}\n\n/**\n * Converts the preset's settings to arguments as though passed on the command\n * line, skipping any arguments the user specified on the command line.\n */\nfunction argsFromPreset<\n TFlags extends Interfaces.FlagOutput,\n TGlobalFlags extends Interfaces.FlagOutput,\n TArgs extends Interfaces.OutputArgs,\n>(\n preset: JsonMap,\n options: Interfaces.Input<TFlags, TGlobalFlags> | undefined,\n noDefaultsResult: Interfaces.ParserOutput<TFlags, TArgs>,\n): string[] {\n const args: string[] = []\n for (const [label, value] of Object.entries(preset)) {\n const flagIsRelevantToCommand = options?.flags && Object.prototype.hasOwnProperty.call(options.flags, label)\n const userSpecifiedThisFlag =\n noDefaultsResult.flags && Object.prototype.hasOwnProperty.call(noDefaultsResult.flags, label)\n if (flagIsRelevantToCommand && !userSpecifiedThisFlag) {\n if (typeof value === 'boolean') {\n if (value === true) {\n args.push(`--${label}`)\n } else {\n throw new Abort(\n content`Presets can only specify true for boolean flags. Attempted to set ${token.yellow(label)} to false.`,\n )\n }\n } else if (Array.isArray(value)) {\n value.forEach((element) => args.push(`--${label}`, `${element}`))\n } else {\n args.push(`--${label}`, `${value}`)\n }\n }\n }\n return args\n}\n\nexport default BaseCommand\n"]}
1
+ {"version":3,"file":"base-command.js","sourceRoot":"","sources":["../../../src/public/node/base-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAE,2CAA2C,EAAC,MAAM,oBAAoB,CAAA;AAC5F,OAAO,EAAC,wBAAwB,EAAC,MAAM,cAAc,CAAA;AAErD,OAAO,EAAC,aAAa,EAAC,MAAM,4BAA4B,CAAA;AACxD,OAAO,EAAC,KAAK,EAAC,MAAM,gBAAgB,CAAA;AACpC,OAAO,EAAC,SAAS,EAAC,MAAM,mBAAmB,CAAA;AAC3C,OAAO,EAAC,OAAO,EAAE,IAAI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AK,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,CAC5G,CAAA;iBACF;aACF;iBAAM,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;gBAC/B,KAAK,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,KAAK,EAAE,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC,CAAA;aAClE;iBAAM;gBACL,IAAI,CAAC,IAAI,CAAC,KAAK,KAAK,EAAE,EAAE,GAAG,KAAK,EAAE,CAAC,CAAA;aACpC;SACF;KACF;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAED,eAAe,WAAW,CAAA","sourcesContent":["import {errorHandler, registerCleanBugsnagErrorsFromWithinPlugins} from './error-handler.js'\nimport {loadPresetsFromDirectory} from './presets.js'\nimport {JsonMap} from '../../private/common/json.js'\nimport {isDevelopment} from '../../environment/local.js'\nimport {Abort} from '../../error.js'\nimport {addPublic} from '../../metadata.js'\nimport {content, info, token} from '../../output.js'\nimport {hashString} from '../../public/node/crypto.js'\nimport {isTruthy} from '../../environment/utilities.js'\nimport {Command, Interfaces} from '@oclif/core'\n\ninterface PresettableFlags {\n preset?: string\n path?: string\n}\n\nabstract class BaseCommand extends Command {\n public static analyticsNameOverride(): string | undefined {\n return undefined\n }\n\n async catch(error: Error & {exitCode?: number | undefined}): Promise<void> {\n await errorHandler(error, this.config)\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n protected async init(): Promise<any> {\n this.exitWithTimestampWhenEnvVariablePresent()\n if (!isDevelopment()) {\n // This function runs just prior to `run`\n await registerCleanBugsnagErrorsFromWithinPlugins(this.config)\n }\n return super.init()\n }\n\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\n protected exitWithTimestampWhenEnvVariablePresent() {\n if (isTruthy(process.env.SHOPIFY_CLI_ENV_STARTUP_PERFORMANCE_RUN)) {\n info(`\n SHOPIFY_CLI_TIMESTAMP_START\n { \"timestamp\": ${Date.now()} }\n SHOPIFY_CLI_TIMESTAMP_END\n `)\n process.exit(0)\n }\n }\n\n protected async parse<\n TFlags extends Interfaces.FlagOutput & {path?: string; verbose?: boolean},\n TGlobalFlags extends Interfaces.FlagOutput,\n TArgs extends Interfaces.OutputArgs,\n >(\n options?: Interfaces.Input<TFlags, TGlobalFlags>,\n argv?: string[],\n ): Promise<Interfaces.ParserOutput<TFlags, TGlobalFlags, TArgs>> {\n let result = await super.parse<TFlags, TGlobalFlags, TArgs>(options, argv)\n result = await this.resultWithPreset<TFlags, TGlobalFlags, TArgs>(result, options, argv)\n await addFromParsedFlags(result.flags)\n return result\n }\n\n protected async resultWithPreset<\n TFlags extends Interfaces.FlagOutput & {path?: string; verbose?: boolean},\n TGlobalFlags extends Interfaces.FlagOutput,\n TArgs extends Interfaces.OutputArgs,\n >(\n originalResult: Interfaces.ParserOutput<TFlags, TGlobalFlags, TArgs>,\n options?: Interfaces.Input<TFlags, TGlobalFlags>,\n argv?: string[],\n ): Promise<Interfaces.ParserOutput<TFlags, TGlobalFlags, TArgs>> {\n // If no preset is specified, don't modify the results\n const flags = originalResult.flags as PresettableFlags\n if (!flags.preset) return originalResult\n\n // If the specified preset isn't found, don't modify the results\n const presets = await loadPresetsFromDirectory(await this.presetsPath(flags), {findUp: this.findUpForPresets()})\n const preset = presets[flags.preset]\n if (!preset) return originalResult\n\n // Parse using noDefaultsOptions to derive a list of flags specified as\n // command-line arguments.\n const noDefaultsResult = await super.parse<TFlags, TGlobalFlags, TArgs>(noDefaultsOptions(options), argv)\n\n // Add the preset's settings to argv and pass them to `super.parse`. This\n // invokes oclif's validation system without breaking the oclif black box.\n // Replace the original result with this one.\n const result = await super.parse<TFlags, TGlobalFlags, TArgs>(options, [\n // Need to specify argv default because we're merging with argsFromPreset.\n ...(argv || this.argv),\n ...argsFromPreset<TFlags, TGlobalFlags, TArgs>(preset, options, noDefaultsResult),\n ])\n\n // Report successful application of the preset.\n reportPresetApplication<TFlags, TGlobalFlags, TArgs>(noDefaultsResult.flags, result.flags, flags.preset, preset)\n\n return result\n }\n\n protected async presetsPath(rawFlags: {path?: string}): Promise<string> {\n return rawFlags.path || process.cwd()\n }\n\n protected findUpForPresets(): boolean {\n return true\n }\n}\n\nexport async function addFromParsedFlags(flags: {path?: string; verbose?: boolean}): Promise<void> {\n await addPublic(() => ({\n cmd_all_verbose: flags.verbose,\n cmd_all_path_override: flags.path !== undefined,\n cmd_all_path_override_hash: flags.path === undefined ? undefined : hashString(flags.path),\n }))\n}\n\n/**\n * Any flag which is:\n *\n * 1. Present in the final set of flags\n * 2. Specified in the preset\n * 3. Not specified by the user as a command line argument\n *\n * should be reported.\n *\n * It doesn't matter if the preset flag's value was the same as the default; from\n * the user's perspective, they want to know their preset was applied.\n */\nfunction reportPresetApplication<\n TFlags extends Interfaces.FlagOutput,\n TGlobalFlags extends Interfaces.FlagOutput,\n TArgs extends Interfaces.OutputArgs,\n>(\n noDefaultsFlags: Interfaces.ParserOutput<TFlags, TGlobalFlags, TArgs>['flags'],\n flagsWithPresets: Interfaces.ParserOutput<TFlags, TGlobalFlags, TArgs>['flags'],\n presetName: string,\n preset: JsonMap,\n): void {\n const changes: JsonMap = {}\n for (const [name, value] of Object.entries(flagsWithPresets)) {\n const userSpecifiedThisFlag = Object.prototype.hasOwnProperty.call(noDefaultsFlags, name)\n const presetContainsFlag = Object.prototype.hasOwnProperty.call(preset, name)\n if (!userSpecifiedThisFlag && presetContainsFlag) changes[name] = value\n }\n if (Object.keys(changes).length === 0) return\n info(content`Using applicable flags from the preset ${token.yellow(presetName)}:\n\n${Object.entries(changes)\n .map(([name, value]) => `• ${name} = ${value}`)\n .join('\\n')}\\n`)\n}\n\n/**\n * Strips the defaults from configured flags. For example, if flags contains:\n *\n * ```\n * someFlag: Flags.boolean({\n * description: 'some flag',\n * default: false\n * })\n * ```\n *\n * it becomes:\n *\n * ```\n * someFlag: Flags.boolean({\n * description: 'some flag'\n * })\n * ```\n *\n * If we parse using this configuration, the only specified flags will be those\n * the user actually passed on the command line.\n */\nfunction noDefaultsOptions<TFlags extends Interfaces.FlagOutput, TGlobalFlags extends Interfaces.FlagOutput>(\n options: Interfaces.Input<TFlags, TGlobalFlags> | undefined,\n): Interfaces.Input<TFlags, TGlobalFlags> | undefined {\n if (!options?.flags) return options\n return {\n ...options,\n flags: Object.fromEntries(\n Object.entries(options.flags).map(([label, settings]) => {\n const copiedSettings = {...(settings as {default?: unknown})}\n delete copiedSettings.default\n return [label, copiedSettings]\n }),\n ) as Interfaces.FlagInput<TFlags>,\n }\n}\n\n/**\n * Converts the preset's settings to arguments as though passed on the command\n * line, skipping any arguments the user specified on the command line.\n */\nfunction argsFromPreset<\n TFlags extends Interfaces.FlagOutput,\n TGlobalFlags extends Interfaces.FlagOutput,\n TArgs extends Interfaces.OutputArgs,\n>(\n preset: JsonMap,\n options: Interfaces.Input<TFlags, TGlobalFlags> | undefined,\n noDefaultsResult: Interfaces.ParserOutput<TFlags, TArgs>,\n): string[] {\n const args: string[] = []\n for (const [label, value] of Object.entries(preset)) {\n const flagIsRelevantToCommand = options?.flags && Object.prototype.hasOwnProperty.call(options.flags, label)\n const userSpecifiedThisFlag =\n noDefaultsResult.flags && Object.prototype.hasOwnProperty.call(noDefaultsResult.flags, label)\n if (flagIsRelevantToCommand && !userSpecifiedThisFlag) {\n if (typeof value === 'boolean') {\n if (value === true) {\n args.push(`--${label}`)\n } else {\n throw new Abort(\n content`Presets can only specify true for boolean flags. Attempted to set ${token.yellow(label)} to false.`,\n )\n }\n } else if (Array.isArray(value)) {\n value.forEach((element) => args.push(`--${label}`, `${element}`))\n } else {\n args.push(`--${label}`, `${value}`)\n }\n }\n }\n return args\n}\n\nexport default BaseCommand\n"]}
@@ -0,0 +1,42 @@
1
+ /// <reference types="node" />
2
+ /**
3
+ * Generate a random string in Hex format of the provided size.
4
+ *
5
+ * @param size - Number of bytes to be generated.
6
+ * @returns A random string in Hex format.
7
+ */
8
+ export declare function randomHex(size: number): string;
9
+ /**
10
+ * Encode a string in Base64 valid for URLs.
11
+ *
12
+ * @param str - The string to encode.
13
+ * @returns The encoded string.
14
+ */
15
+ export declare function base64URLEncode(str: Buffer): string;
16
+ /**
17
+ * Generate the SHA256 hash of a string.
18
+ *
19
+ * @param str - The string to hash.
20
+ * @returns The SHA256 hash of the string.
21
+ */
22
+ export declare function sha256(str: string): Buffer;
23
+ /**
24
+ * Generate the SHA1 hash of a string.
25
+ *
26
+ * @param str - The string to hash.
27
+ * @returns The SHA1 hash of the string.
28
+ */
29
+ export declare function hashString(str: string): string;
30
+ /**
31
+ * Generate random data of the provided size.
32
+ *
33
+ * @param size - Number of bytes to be generated.
34
+ * @returns A buffer of random data.
35
+ */
36
+ export declare function randomBytes(size: number): Buffer;
37
+ /**
38
+ * Generate a random UUID string.
39
+ *
40
+ * @returns A random UUID string.
41
+ */
42
+ export declare function randomUUID(): string;
@@ -0,0 +1,55 @@
1
+ import crypto from 'crypto';
2
+ /**
3
+ * Generate a random string in Hex format of the provided size.
4
+ *
5
+ * @param size - Number of bytes to be generated.
6
+ * @returns A random string in Hex format.
7
+ */
8
+ export function randomHex(size) {
9
+ return crypto.randomBytes(size).toString('hex');
10
+ }
11
+ /**
12
+ * Encode a string in Base64 valid for URLs.
13
+ *
14
+ * @param str - The string to encode.
15
+ * @returns The encoded string.
16
+ */
17
+ export function base64URLEncode(str) {
18
+ return str.toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/[=]/g, '');
19
+ }
20
+ /**
21
+ * Generate the SHA256 hash of a string.
22
+ *
23
+ * @param str - The string to hash.
24
+ * @returns The SHA256 hash of the string.
25
+ */
26
+ export function sha256(str) {
27
+ return crypto.createHash('sha256').update(str).digest();
28
+ }
29
+ /**
30
+ * Generate the SHA1 hash of a string.
31
+ *
32
+ * @param str - The string to hash.
33
+ * @returns The SHA1 hash of the string.
34
+ */
35
+ export function hashString(str) {
36
+ return crypto.createHash('sha1').update(str).digest('hex');
37
+ }
38
+ /**
39
+ * Generate random data of the provided size.
40
+ *
41
+ * @param size - Number of bytes to be generated.
42
+ * @returns A buffer of random data.
43
+ */
44
+ export function randomBytes(size) {
45
+ return crypto.randomBytes(size);
46
+ }
47
+ /**
48
+ * Generate a random UUID string.
49
+ *
50
+ * @returns A random UUID string.
51
+ */
52
+ export function randomUUID() {
53
+ return crypto.randomUUID();
54
+ }
55
+ //# sourceMappingURL=crypto.js.map