rebilly-js-sdk 62.129.0 → 62.131.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,6 +9,14 @@ const schemaTypes = {
9
9
  REPORTS: 'reports',
10
10
  };
11
11
 
12
+ // Names emitted by openapi-typescript (after the rename in processSchema)
13
+ // that we re-export from the "rebilly-js-sdk" module.
14
+ const openApiSharedTypeNames = ['operations'];
15
+ const openApiPerSchemaTypeNames = (schemaType) => [
16
+ `${schemaType}Paths`,
17
+ `${schemaType}Components`,
18
+ ];
19
+
12
20
  // Takes a schema object and returns the new schema with
13
21
  // adjusted `paths` properties based on the prefix we should remove.
14
22
  // For example, storefront APIs should only include paths with the prefix /storefront
@@ -62,10 +70,20 @@ async function generateTypesFromSchema(schema) {
62
70
  const combinedSDKTypes =
63
71
  coreTypes.sdkTypes + storefrontTypes.sdkTypes + reportsTypes.sdkTypes;
64
72
 
73
+ const moduleReexports = buildModuleReexports([
74
+ ...openApiSharedTypeNames,
75
+ ...openApiPerSchemaTypeNames(schemaTypes.CORE),
76
+ ...openApiPerSchemaTypeNames(schemaTypes.STOREFRONT),
77
+ ...openApiPerSchemaTypeNames(schemaTypes.REPORTS),
78
+ ...coreTypes.sdkTypeNames,
79
+ ...storefrontTypes.sdkTypeNames,
80
+ ...reportsTypes.sdkTypeNames,
81
+ ]);
82
+
65
83
  console.log(
66
84
  '🍹 Mixing openapi-typescript types and custom SDK types into the same file (/typings/rebilly/index.d.ts)',
67
85
  );
68
- mergeTypesIntoTemplate(combinedApiTypes, combinedSDKTypes);
86
+ mergeTypesIntoTemplate(combinedApiTypes, combinedSDKTypes, moduleReexports);
69
87
  }
70
88
 
71
89
  async function processSchema(openApiSchema, schemaType) {
@@ -86,8 +104,9 @@ async function processSchema(openApiSchema, schemaType) {
86
104
  openApiTypes = fixSpecialTypes(openApiTypes);
87
105
 
88
106
  // Generating custom SDK types with custom rebilly script
89
- const sdkTypes = generateSdkTypes(openApiSchema);
90
- return { openApiTypes, sdkTypes };
107
+ const { types: sdkTypes, names: sdkTypeNames } =
108
+ generateSdkTypes(openApiSchema);
109
+ return { openApiTypes, sdkTypes, sdkTypeNames };
91
110
  }
92
111
 
93
112
  function fixProperties(openApiSchema) {
@@ -126,11 +145,29 @@ function createTemporaryTypingsDirectory() {
126
145
  }
127
146
  }
128
147
 
129
- function mergeTypesIntoTemplate(openApiTypes, sdkTypes) {
148
+ // Builds the body of the `declare module "rebilly-js-sdk"` block:
149
+ // one `export type X = rebilly.X` alias per name, deduplicated.
150
+ function buildModuleReexports(names) {
151
+ const seen = new Set();
152
+ return names
153
+ .filter((name) => {
154
+ if (seen.has(name)) return false;
155
+ seen.add(name);
156
+ return true;
157
+ })
158
+ .map((name) => `export type ${name} = rebilly.${name};`)
159
+ .join('\n ');
160
+ }
161
+
162
+ function mergeTypesIntoTemplate(openApiTypes, sdkTypes, moduleReexports) {
130
163
  const templateFilename = './types-generation/template.d.ts';
131
164
  let templateData = readFileSync(templateFilename, 'utf-8');
132
165
  templateData = templateData.replaceAll('//<open-api-types>', openApiTypes);
133
166
  templateData = templateData.replaceAll('//<sdk-types>', sdkTypes);
167
+ templateData = templateData.replaceAll(
168
+ '//<module-reexports>',
169
+ moduleReexports,
170
+ );
134
171
 
135
172
  createTemporaryTypingsDirectory();
136
173
 
@@ -1,3 +1,8 @@
1
+ /**
2
+ * @deprecated Import types from `"rebilly-js-sdk"` directly instead of accessing them via the `rebilly` global namespace.
3
+ * Example: `import type { GetCustomerCollectionRequest } from "rebilly-js-sdk"`.
4
+ * The `rebilly` global namespace is kept for backwards compatibility and will be removed in a future major version.
5
+ */
1
6
  declare namespace rebilly {
2
7
  type Expandable<T> = Partial<T> & { expand?: string };
3
8
 
@@ -8,6 +13,12 @@ declare namespace rebilly {
8
13
  //<open-api-types>
9
14
  }
10
15
 
16
+ declare module "rebilly-js-sdk" {
17
+ export type Expandable<T> = rebilly.Expandable<T>;
18
+
19
+ //<module-reexports>
20
+ }
21
+
11
22
  declare module "rebilly-js-sdk/types" {
12
23
  export = rebilly;
13
24
  }