@imtbl/sdk 0.31.0 → 0.31.2-alpha

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 (52) hide show
  1. package/.eslintrc +13 -0
  2. package/.gitignore +8 -0
  3. package/blockchain_data.js +1 -0
  4. package/checkout_sdk.js +9 -0
  5. package/config.js +1 -0
  6. package/dist/browser/checkout/sdk.js +1 -1
  7. package/dist/index.browser.js +3 -3
  8. package/dist/index.browser.js.map +1 -1
  9. package/immutablex_client.js +1 -0
  10. package/index.cjs +9 -0
  11. package/index.d.ts +18603 -0
  12. package/index.js +9 -0
  13. package/module-release.json +30 -0
  14. package/orderbook.js +1 -0
  15. package/package.json +24 -18
  16. package/passport.js +1 -0
  17. package/provider.js +1 -0
  18. package/rollup.config.js +158 -0
  19. package/scripts/copyBrowserBundles.js +62 -0
  20. package/scripts/generate-package-list.sh +5 -0
  21. package/scripts/generateIndex.js +44 -0
  22. package/scripts/updateDependencies.js +137 -0
  23. package/scripts/updateExports.js +62 -0
  24. package/src/blockchain_data.ts +1 -0
  25. package/src/checkout_sdk.ts +1 -0
  26. package/src/checkout_widgets.ts +1 -0
  27. package/src/config.ts +1 -0
  28. package/src/immutablex_client.ts +1 -0
  29. package/src/index.ts +7 -0
  30. package/src/orderbook.ts +1 -0
  31. package/src/passport.ts +1 -0
  32. package/src/provider.ts +1 -0
  33. package/tsconfig.json +27 -0
  34. package/typedoc.json +4 -0
  35. package/workspace-packages.json +31 -0
  36. package/dist/blockchain_data.js +0 -4010
  37. package/dist/checkout_sdk.js +0 -26016
  38. package/dist/config.js +0 -37
  39. package/dist/immutablex_client.js +0 -523
  40. package/dist/index.cjs +0 -34452
  41. package/dist/index.js +0 -34424
  42. package/dist/orderbook.js +0 -1583
  43. package/dist/passport.js +0 -9159
  44. package/dist/provider.js +0 -1165
  45. /package/{dist/blockchain_data.d.ts → blockchain_data.d.ts} +0 -0
  46. /package/{dist/checkout_sdk.d.ts → checkout_sdk.d.ts} +0 -0
  47. /package/{dist/config.d.ts → config.d.ts} +0 -0
  48. /package/{dist/immutablex_client.d.ts → immutablex_client.d.ts} +0 -0
  49. /package/{dist/index.d.ts → index.d.cts} +0 -0
  50. /package/{dist/orderbook.d.ts → orderbook.d.ts} +0 -0
  51. /package/{dist/passport.d.ts → passport.d.ts} +0 -0
  52. /package/{dist/provider.d.ts → provider.d.ts} +0 -0
@@ -0,0 +1,158 @@
1
+ import typescript from '@rollup/plugin-typescript';
2
+ import { nodeResolve } from '@rollup/plugin-node-resolve';
3
+ import { readFileSync } from 'fs';
4
+ import commonJs from '@rollup/plugin-commonjs';
5
+ import json from '@rollup/plugin-json';
6
+ import dts from 'rollup-plugin-dts';
7
+ import replace from '@rollup/plugin-replace';
8
+ import pkg from './package.json' assert { type: 'json' };
9
+ import moduleReleases from './module-release.json' assert { type: 'json' };
10
+ import terser from '@rollup/plugin-terser';
11
+ import nodePolyfills from 'rollup-plugin-polyfill-node';
12
+
13
+
14
+ // RELEASE_TYPE environment variable is set by the CI/CD pipeline
15
+ const releaseType = process.env.RELEASE_TYPE || 'alpha';
16
+
17
+ const packages = JSON.parse(
18
+ readFileSync('./workspace-packages.json', { encoding: 'utf8' })
19
+ );
20
+
21
+ const getPackages = () => packages.map((pkg) => pkg.name);
22
+
23
+ // Get relevant files to bundle
24
+ const getFilesToBuild = () => {
25
+ // Always build the index file
26
+ const files = ['index'];
27
+
28
+ const moduleFiles = Object.keys(moduleReleases.modules);
29
+ if (releaseType === 'alpha') {
30
+ return [...files, ...moduleFiles];
31
+ }
32
+
33
+ const returnModules = moduleFiles.filter(
34
+ (file) => moduleReleases.modules[file] === 'prod'
35
+ );
36
+ return [...files, ...returnModules];
37
+ };
38
+
39
+ const getFileBuild = (inputFilename) => [
40
+ {
41
+ input: `./src/${inputFilename}.ts`,
42
+ output: {
43
+ dir: './',
44
+ format: 'es',
45
+ },
46
+ plugins: [
47
+ nodeResolve({
48
+ resolveOnly: getPackages(),
49
+ }),
50
+ commonJs(),
51
+ json(),
52
+ typescript({
53
+ declaration: true,
54
+ declarationDir: './dist/types',
55
+ }),
56
+ replace({
57
+ exclude: 'node_modules/**',
58
+ preventAssignment: true,
59
+ __SDK_VERSION__: pkg.version,
60
+ }),
61
+ terser(),
62
+ ],
63
+ },
64
+ {
65
+ input: `./dist/types/${inputFilename}.d.ts`,
66
+ output: {
67
+ file: `./${inputFilename}.d.ts`,
68
+ format: 'es',
69
+ },
70
+ plugins: [
71
+ dts({
72
+ respectExternal: true,
73
+ }),
74
+ ],
75
+ },
76
+ ];
77
+
78
+ const buildBundles = () => {
79
+ const modules = [];
80
+ const filesToBuild = getFilesToBuild();
81
+ for (const file of filesToBuild) {
82
+ modules.push(...getFileBuild(file));
83
+ }
84
+ return modules;
85
+ };
86
+
87
+ export default [
88
+ // Main build entry
89
+ {
90
+ input: 'src/index.ts',
91
+ output: {
92
+ file: './index.cjs',
93
+ format: 'cjs',
94
+ },
95
+ plugins: [
96
+ nodeResolve({
97
+ resolveOnly: getPackages(),
98
+ }),
99
+ json(),
100
+ commonJs(),
101
+ typescript({
102
+ declaration: true,
103
+ declarationDir: './dist/types/cjs',
104
+ }),
105
+ replace({
106
+ exclude: 'node_modules/**',
107
+ preventAssignment: true,
108
+ __SDK_VERSION__: pkg.version,
109
+ }),
110
+ terser(),
111
+ ],
112
+ },
113
+ {
114
+ input: `./dist/types/cjs/index.d.ts`,
115
+ output: {
116
+ file: `./index.d.cts`
117
+ },
118
+ plugins: [
119
+ dts({
120
+ respectExternal: true,
121
+ }),
122
+ ],
123
+ },
124
+ // Browser Bundle
125
+ {
126
+ input: 'src/index.ts',
127
+ output: {
128
+ file: 'dist/index.browser.js',
129
+ format: 'umd',
130
+ sourcemap: true,
131
+ name: 'immutable',
132
+ },
133
+ plugins: [
134
+ nodeResolve({
135
+ jsnext: true,
136
+ main: true,
137
+ browser: true,
138
+ }),
139
+ nodePolyfills(),
140
+ commonJs(),
141
+ typescript(),
142
+ json(),
143
+ replace({
144
+ // Can't exclude node_modules here because some dependencies use process.env.NODE_ENV
145
+ // this breaks in browsers
146
+ preventAssignment: true,
147
+ __SDK_VERSION__: pkg.version,
148
+
149
+ // This breaks in a dex dependency, so manually replacing it.
150
+ 'process.env.NODE_ENV': '"production"'
151
+ }),
152
+ terser(),
153
+ ],
154
+ },
155
+
156
+ // Export ES Modules
157
+ ...buildBundles(),
158
+ ];
@@ -0,0 +1,62 @@
1
+ import fs from 'fs';
2
+ import * as glob from 'glob';
3
+ import path from 'path';
4
+ import pkg from '../package.json' assert { type: 'json' };
5
+
6
+ const dirname = path.dirname(new URL(import.meta.url).pathname);
7
+
8
+ const SDK_VERSION = '__SDK_VERSION__';
9
+
10
+ const getFiles = () => {
11
+ // Read the JSON file
12
+ const moduleReleaseData = fs.readFileSync(
13
+ path.join(dirname, '..', 'module-release.json'),
14
+ );
15
+ const fileList = JSON.parse(moduleReleaseData.toString()).fileCopy;
16
+ return fileList;
17
+ };
18
+
19
+ function findAndReplace(data, find, replace) {
20
+ if (!data.includes(find)) return data;
21
+ return data.replace(new RegExp(find, 'g'), replace);
22
+ }
23
+
24
+ const main = () => {
25
+ const fileList = getFiles();
26
+
27
+ const releaseType = process.env.RELEASE_TYPE || 'alpha';
28
+
29
+ // Loop through each item in the list
30
+ fileList.forEach((item) => {
31
+ // Check if this item should be copied based on its "stage" property and RELEASE_TYPE environment variable
32
+ if (
33
+ releaseType === 'alpha'
34
+ || (releaseType !== 'alpha' && item.stage === 'prod')
35
+ ) {
36
+ // Find all matching files using glob pattern matching
37
+ const srcPath = path.join(dirname, '..', item.src);
38
+ const files = glob.sync(srcPath);
39
+
40
+ // Copy each file to its destination location
41
+ files.forEach((sourceFile) => {
42
+ const destPath = path.join(dirname, '..', item.dest);
43
+
44
+ const directoryPath = path.dirname(destPath);
45
+ if (!fs.existsSync(directoryPath)) {
46
+ fs.mkdirSync(directoryPath, { recursive: true });
47
+ }
48
+
49
+ let data = fs.readFileSync(sourceFile, 'utf-8');
50
+
51
+ data = findAndReplace(data, SDK_VERSION, pkg.version);
52
+ // Add more findAndReplace if and when needed
53
+ // data = findAndReplace(data, <find>, <replace>);
54
+
55
+ fs.writeFileSync(destPath, data);
56
+ });
57
+ }
58
+ });
59
+ };
60
+
61
+ // Execute
62
+ main();
@@ -0,0 +1,5 @@
1
+ #!/bin/sh
2
+
3
+ set -e
4
+
5
+ yarn workspaces list --json | sed -e ' $ ! s/}/},/' | sed '$ s/$/]/' | sed '1 s/^/[/' > workspace-packages.json
@@ -0,0 +1,44 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+
4
+ const dirname = path.dirname(new URL(import.meta.url).pathname);
5
+
6
+ // Read the JSON file
7
+ const fileData = fs.readFileSync(
8
+ path.join(dirname, '..', 'module-release.json'),
9
+ );
10
+ const moduleData = JSON.parse(fileData);
11
+
12
+ // Get the release type from the environment variable or default to 'alpha'
13
+ const releaseType = process.env.RELEASE_TYPE || 'alpha';
14
+
15
+ // Generate the index.ts file contents based on the release type
16
+ let indexFileContent = '';
17
+ Object.keys(moduleData.modules).forEach((moduleName) => {
18
+ const moduleReleaseType = moduleData.modules[moduleName];
19
+
20
+ if (
21
+ releaseType === 'alpha'
22
+ || (releaseType !== 'alpha' && moduleReleaseType === 'prod')
23
+ ) {
24
+ // Split underscores and capitalize each word from the second
25
+ const moduleNameCapitalized = moduleName.split('_')
26
+ .map((part, index) => {
27
+ if (index === 0) {
28
+ return part;
29
+ }
30
+ return part.charAt(0).toUpperCase() + part.slice(1);
31
+ })
32
+ .join('');
33
+
34
+ const modulePath = `./${moduleName}`;
35
+ const exportStatement = `export * as ${moduleNameCapitalized} from '${modulePath}';\n`;
36
+ indexFileContent += exportStatement;
37
+ }
38
+ });
39
+
40
+ // Write the index.ts file
41
+ fs.writeFileSync(
42
+ path.join(process.cwd(), 'src', 'index.ts'),
43
+ indexFileContent,
44
+ );
@@ -0,0 +1,137 @@
1
+ //@ts-check
2
+ import { getPluginConfiguration } from '@yarnpkg/cli';
3
+ import { Configuration, Project } from '@yarnpkg/core';
4
+ import semver from 'semver';
5
+ import fs from 'fs';
6
+ import path from 'path';
7
+
8
+ const __dirname = path.resolve();
9
+ const SDK_PACKAGE = '@imtbl/sdk';
10
+
11
+ const getWorkspacePackages = () => {
12
+ const workspacePackages = JSON.parse(
13
+ fs.readFileSync(path.resolve(__dirname, 'workspace-packages.json'), {
14
+ encoding: 'utf8',
15
+ })
16
+ ).map((pkg) => pkg.name);
17
+ return workspacePackages;
18
+ };
19
+ const workspacePackages = getWorkspacePackages();
20
+
21
+ // Update the map with the dependency if it doesn't exist, or if the
22
+ // version is greater than the existing version
23
+ const updateVersion = (map, dependency, version) => {
24
+ // Don't add any workspace packages as a dependency
25
+ if (workspacePackages.includes(dependency)) return;
26
+
27
+ const existingVersion = map.get(dependency);
28
+
29
+ if (
30
+ !existingVersion ||
31
+ semver.gt(parseVersion(version), parseVersion(existingVersion))
32
+ ) {
33
+ map.set(dependency, version);
34
+ }
35
+ };
36
+
37
+ // Recusively go through a workspace, and return it's dependencies
38
+ // and peer dependencies
39
+ const collectDependenciesRecusively = async (sdkWorkspace) => {
40
+ const dependenciesMap = new Map();
41
+ const peerDependenciesMap = new Map();
42
+
43
+ // Recursively go through a workspace and update the dependencies
44
+ const processWorkspace = (workspace) => {
45
+ const manifest = workspace.manifest;
46
+ const { dependencies, peerDependencies, devDependencies } = manifest;
47
+
48
+ // Dev dependencies, only check if they're workspace packages
49
+ // And then process them
50
+ devDependencies.forEach((dep) => {
51
+ const depWorkspace = workspace.project.tryWorkspaceByIdent(dep);
52
+ if (depWorkspace) {
53
+ processWorkspace(depWorkspace);
54
+ }
55
+ });
56
+
57
+ // If sdkpackage, exit early
58
+ if (manifest.raw.name === SDK_PACKAGE) return;
59
+
60
+ // UpdateVersion for dependencies
61
+ dependencies.forEach((dep) => {
62
+ updateVersion(
63
+ dependenciesMap,
64
+ packageName(dep.scope, dep.name),
65
+ dep.range
66
+ );
67
+
68
+ const depWorkspace = workspace.project.tryWorkspaceByIdent(dep);
69
+ if (depWorkspace) {
70
+ processWorkspace(depWorkspace);
71
+ }
72
+ });
73
+
74
+ // Same for peerDependencies, but don't recurse
75
+ peerDependencies.forEach((dep) =>
76
+ updateVersion(
77
+ peerDependenciesMap,
78
+ packageName(dep.scope, dep.name),
79
+ dep.range
80
+ )
81
+ );
82
+ };
83
+
84
+ // Start the recursive process
85
+ processWorkspace(sdkWorkspace);
86
+
87
+ return {
88
+ dependencies: Object.fromEntries(dependenciesMap.entries()),
89
+ peerDependencies: Object.fromEntries(peerDependenciesMap.entries()),
90
+ };
91
+ };
92
+
93
+ // Takes a scope and a package name and returns a scoped package name
94
+ const packageName = (scope, name) => {
95
+ return scope ? `@${scope}/${name}` : name;
96
+ };
97
+
98
+ // Remove ranges to parse just version
99
+ const parseVersion = (version) => {
100
+ return version.replace(/^[^\d]*/, '');
101
+ };
102
+
103
+ // Update package.json with the dependencies and peerDependencies
104
+ const main = async () => {
105
+ const cwd = process.cwd();
106
+ const pluginConfiguration = getPluginConfiguration();
107
+ const configuration = await Configuration.find(cwd, pluginConfiguration);
108
+ const { project } = await Project.find(configuration, cwd);
109
+
110
+ const targetWorkspace = project.workspaces.find(
111
+ (workspace) => workspace.manifest.raw.name === SDK_PACKAGE
112
+ );
113
+
114
+ if (!targetWorkspace) {
115
+ throw Error(`${SDK_PACKAGE} package not found`);
116
+ }
117
+
118
+ const { dependencies, peerDependencies } =
119
+ await collectDependenciesRecusively(targetWorkspace);
120
+
121
+ const packageJson = JSON.parse(
122
+ fs.readFileSync(path.resolve(__dirname, 'package.json'), 'utf8')
123
+ );
124
+
125
+ packageJson.dependencies = dependencies;
126
+ // Only add peerDependencies if there are any
127
+ if (Object.values(peerDependencies).length > 0) {
128
+ packageJson.peerDependencies = peerDependencies;
129
+ }
130
+
131
+ fs.writeFileSync(
132
+ path.resolve(__dirname, 'package.json'),
133
+ JSON.stringify(packageJson, null, 2)
134
+ );
135
+ };
136
+
137
+ main();
@@ -0,0 +1,62 @@
1
+ /* eslint-disable */
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+
5
+ const __dirname = path.dirname(new URL(import.meta.url).pathname);
6
+
7
+ // Read the module-release.json file
8
+ const moduleReleaseData = fs.readFileSync(
9
+ path.join(__dirname, '..', 'module-release.json')
10
+ );
11
+ const moduleData = JSON.parse(moduleReleaseData);
12
+
13
+ // Get the release type from the environment variable or default to 'alpha'
14
+ const releaseType = process.env.RELEASE_TYPE || 'alpha';
15
+
16
+ // Update the package.json exports based on the release type
17
+ const packageJsonPath = path.join(__dirname, '..', 'package.json');
18
+ const packageJsonData = fs.readFileSync(packageJsonPath, 'utf8');
19
+ const packageJson = JSON.parse(packageJsonData);
20
+
21
+ const exports = {
22
+ './package.json': './package.json',
23
+ '.': {
24
+ imports: {
25
+ types: './index.d.ts',
26
+ default: './index.js',
27
+ },
28
+ require: {
29
+ types: './index.d.cts',
30
+ default: './index.cjs',
31
+ }
32
+ },
33
+ };
34
+
35
+ for (const moduleName in moduleData.modules) {
36
+ // if (moduleName === 'config') {
37
+ // continue; // Skip config module as it's explicitly defined for '.'
38
+ // }
39
+
40
+ const moduleReleaseType = moduleData.modules[moduleName];
41
+
42
+ if (
43
+ releaseType === 'alpha' ||
44
+ (releaseType !== 'alpha' && moduleReleaseType === 'prod')
45
+ ) {
46
+ const moduleExport = `./${moduleName}`;
47
+ const modulePath = `./${moduleName}.js`;
48
+ const typesPath = `./${moduleName}.d.ts`;
49
+
50
+ exports[moduleExport] = {
51
+ types: typesPath,
52
+ import: modulePath,
53
+ };
54
+ }
55
+ }
56
+
57
+ packageJson.exports = exports;
58
+
59
+ // Write the updated package.json file
60
+ fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
61
+
62
+ console.log('Package.json exports updated successfully!');
@@ -0,0 +1 @@
1
+ export * from '@imtbl/blockchain-data';
@@ -0,0 +1 @@
1
+ export * from '@imtbl/checkout-sdk';
@@ -0,0 +1 @@
1
+ export * from '@imtbl/checkout-widgets';
package/src/config.ts ADDED
@@ -0,0 +1 @@
1
+ export * from '@imtbl/config';
@@ -0,0 +1 @@
1
+ export * from '@imtbl/immutablex-client';
package/src/index.ts ADDED
@@ -0,0 +1,7 @@
1
+ export * as config from './config';
2
+ export * as blockchainData from './blockchain_data';
3
+ export * as immutablexClient from './immutablex_client';
4
+ export * as passport from './passport';
5
+ export * as orderbook from './orderbook';
6
+ export * as provider from './provider';
7
+ export * as checkoutSdk from './checkout_sdk';
@@ -0,0 +1 @@
1
+ export * from '@imtbl/orderbook';
@@ -0,0 +1 @@
1
+ export * from '@imtbl/passport';
@@ -0,0 +1 @@
1
+ export * from '@imtbl/provider';
package/tsconfig.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "compilerOptions": {
3
+ "baseUrl": "./src",
4
+ "outDir": "./dist",
5
+ "rootDirs": ["src"],
6
+ "target": "es2022",
7
+ "module": "esnext",
8
+ "moduleResolution": "node",
9
+ "noEmit": true,
10
+ "allowJs": false,
11
+ "removeComments": false,
12
+ "strict": true,
13
+ "forceConsistentCasingInFileNames": false,
14
+ "allowSyntheticDefaultImports": true,
15
+ "esModuleInterop": true,
16
+ "declaration": false,
17
+ "resolveJsonModule": true,
18
+ "skipLibCheck": true
19
+ },
20
+ "include": ["src"],
21
+ "exclude": [
22
+ "node_modules",
23
+ "dist",
24
+ "src/modules/provider/sample-app",
25
+ "src/modules/checkout"
26
+ ]
27
+ }
package/typedoc.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": ["../typedoc.base.json"],
3
+ "entryPoints": ["src/index.ts"],
4
+ }
@@ -0,0 +1,31 @@
1
+ [{"location":".","name":"ts-immutable-sdk"},
2
+ {"location":"packages/blockchain-data/sample-app","name":"blockchain-data-sample-app"},
3
+ {"location":"packages/blockchain-data/sdk","name":"@imtbl/blockchain-data"},
4
+ {"location":"packages/checkout/sdk","name":"@imtbl/checkout-sdk"},
5
+ {"location":"packages/checkout/sdk-sample-app","name":"@imtbl/checkout-sdk-sample-app"},
6
+ {"location":"packages/checkout/widgets-lib","name":"@imtbl/checkout-widgets"},
7
+ {"location":"packages/checkout/widgets-sample-app","name":"@imtbl/checkout-widgets-sample-app"},
8
+ {"location":"packages/config","name":"@imtbl/config"},
9
+ {"location":"packages/economy/playground","name":"@imtbl/economy-playground"},
10
+ {"location":"packages/economy/sdk","name":"@imtbl/economy"},
11
+ {"location":"packages/economy/services","name":"@imtbl/economy-services"},
12
+ {"location":"packages/game-bridge","name":"@imtbl/game-bridge"},
13
+ {"location":"packages/immutablex_client","name":"@imtbl/immutablex-client"},
14
+ {"location":"packages/internal/bridge/bridge-sample-app","name":"bridge-sample-app"},
15
+ {"location":"packages/internal/bridge/sdk","name":"@imtbl/bridge-sdk"},
16
+ {"location":"packages/internal/cryptofiat","name":"@imtbl/cryptofiat"},
17
+ {"location":"packages/internal/dex/sdk","name":"@imtbl/dex-sdk"},
18
+ {"location":"packages/internal/dex/sdk-sample-app","name":"sdk-sample-app"},
19
+ {"location":"packages/internal/economy-building-blocks/playground","name":"@imtbl/economy-building-blocks-playground"},
20
+ {"location":"packages/internal/factory/factory-sample-app","name":"factory-sample-app"},
21
+ {"location":"packages/internal/factory/sdk","name":"@imtbl/factory-sdk"},
22
+ {"location":"packages/internal/generated-clients","name":"@imtbl/generated-clients"},
23
+ {"location":"packages/internal/guardian","name":"@imtbl/guardian"},
24
+ {"location":"packages/internal/toolkit","name":"@imtbl/toolkit"},
25
+ {"location":"packages/internal/version-check","name":"@imtbl/version-check"},
26
+ {"location":"packages/orderbook","name":"@imtbl/orderbook"},
27
+ {"location":"packages/passport/sdk","name":"@imtbl/passport"},
28
+ {"location":"packages/passport/sdk-sample-app","name":"@imtbl/passport-sdk-sample-app"},
29
+ {"location":"packages/provider","name":"@imtbl/provider"},
30
+ {"location":"packages/provider/src/sample-app","name":"sample-app"},
31
+ {"location":"sdk","name":"@imtbl/sdk"}]