payment-kit 1.13.40 → 1.13.41

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.
@@ -1,3 +1,5 @@
1
+ /* eslint-disable no-await-in-loop */
2
+ import type { QueryInterface } from 'sequelize';
1
3
  import { SequelizeStorage, Umzug } from 'umzug';
2
4
 
3
5
  import { sequelize } from './sequelize';
@@ -13,4 +15,19 @@ export default function migrate() {
13
15
  return umzug.up();
14
16
  }
15
17
 
18
+ type ColumnChanges = Record<string, { name: string; field: any }[]>;
19
+ export async function safeApplyColumnChanges(context: QueryInterface, changes: ColumnChanges) {
20
+ for (const [table, columns] of Object.entries(changes)) {
21
+ const schema = await context.describeTable(table);
22
+ for (const { name, field } of columns) {
23
+ if (!schema[name]) {
24
+ await context.addColumn(table, name, field);
25
+ if (field.defaultValue) {
26
+ await context.bulkUpdate(table, { [name]: field.defaultValue }, {});
27
+ }
28
+ }
29
+ }
30
+ }
31
+ }
32
+
16
33
  export type Migration = typeof umzug._types.migration;
@@ -1,16 +1,25 @@
1
+ /* eslint-disable no-await-in-loop */
1
2
  import { DataTypes } from 'sequelize';
2
3
 
3
- import type { Migration } from '../migrate';
4
+ import { Migration, safeApplyColumnChanges } from '../migrate';
4
5
 
5
6
  export const up: Migration = async ({ context }) => {
6
- await context.addColumn('payment_links', 'nft_mint_settings', { type: DataTypes.JSON, allowNull: true });
7
- await context.addColumn('checkout_sessions', 'payment_intent_data', { type: DataTypes.JSON, allowNull: true });
8
- await context.addColumn('checkout_sessions', 'nft_mint_settings', { type: DataTypes.JSON, allowNull: true });
9
- await context.addColumn('checkout_sessions', 'nft_mint_details', { type: DataTypes.JSON, allowNull: true });
10
- await context.addColumn('checkout_sessions', 'nft_mint_status', {
11
- type: DataTypes.ENUM('disabled', 'pending', 'minted', 'sent', 'error'),
12
- defaultValue: 'disabled',
13
- allowNull: false,
7
+ await safeApplyColumnChanges(context, {
8
+ payment_links: [{ name: 'nft_mint_settings', field: { type: DataTypes.JSON, allowNull: true } }],
9
+ checkout_sessions: [
10
+ { name: 'nft_mint_settings', field: { type: DataTypes.JSON, allowNull: true } },
11
+ { name: 'payment_intent_data', field: { type: DataTypes.JSON, allowNull: true } },
12
+ { name: 'nft_mint_settings', field: { type: DataTypes.JSON, allowNull: true } },
13
+ { name: 'nft_mint_details', field: { type: DataTypes.JSON, allowNull: true } },
14
+ {
15
+ name: 'nft_mint_status',
16
+ field: {
17
+ type: DataTypes.ENUM('disabled', 'pending', 'minted', 'sent', 'error'),
18
+ defaultValue: 'disabled',
19
+ allowNull: false,
20
+ },
21
+ },
22
+ ],
14
23
  });
15
24
  };
16
25
 
@@ -1,9 +1,12 @@
1
+ /* eslint-disable no-await-in-loop */
1
2
  import { DataTypes } from 'sequelize';
2
3
 
3
- import type { Migration } from '../migrate';
4
+ import { Migration, safeApplyColumnChanges } from '../migrate';
4
5
 
5
6
  export const up: Migration = async ({ context }) => {
6
- await context.addColumn('prices', 'upsell', { type: DataTypes.JSON, allowNull: true });
7
+ await safeApplyColumnChanges(context, {
8
+ prices: [{ name: 'upsell', field: { type: DataTypes.JSON, allowNull: true } }],
9
+ });
7
10
  };
8
11
 
9
12
  export const down: Migration = async ({ context }) => {
@@ -1,19 +1,18 @@
1
+ /* eslint-disable no-await-in-loop */
1
2
  import { DataTypes } from 'sequelize';
2
3
 
3
- import type { Migration } from '../migrate';
4
+ import { Migration, safeApplyColumnChanges } from '../migrate';
4
5
 
5
6
  export const up: Migration = async ({ context }) => {
6
- await context.addColumn('products', 'cross_sell', { type: DataTypes.JSON, allowNull: true });
7
- await context.addColumn('checkout_sessions', 'cross_sell_behavior', {
8
- type: DataTypes.ENUM('auto', 'required'),
9
- defaultValue: 'auto',
7
+ await safeApplyColumnChanges(context, {
8
+ products: [{ name: 'cross_sell', field: { type: DataTypes.JSON, allowNull: true } }],
9
+ checkout_sessions: [
10
+ { name: 'cross_sell_behavior', field: { type: DataTypes.ENUM('auto', 'required'), defaultValue: 'auto' } },
11
+ ],
12
+ payment_links: [
13
+ { name: 'cross_sell_behavior', field: { type: DataTypes.ENUM('auto', 'required'), defaultValue: 'auto' } },
14
+ ],
10
15
  });
11
- await context.addColumn('payment_links', 'cross_sell_behavior', {
12
- type: DataTypes.ENUM('auto', 'required'),
13
- defaultValue: 'auto',
14
- });
15
- await context.bulkUpdate('checkout_sessions', { cross_sell_behavior: 'auto' }, {});
16
- await context.bulkUpdate('payment_links', { cross_sell_behavior: 'auto' }, {});
17
16
  };
18
17
 
19
18
  export const down: Migration = async ({ context }) => {
package/blocklet.yml CHANGED
@@ -14,7 +14,7 @@ repository:
14
14
  type: git
15
15
  url: git+https://github.com/blocklet/payment-kit.git
16
16
  specVersion: 1.2.8
17
- version: 1.13.40
17
+ version: 1.13.41
18
18
  logo: logo.png
19
19
  files:
20
20
  - dist
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payment-kit",
3
- "version": "1.13.40",
3
+ "version": "1.13.41",
4
4
  "scripts": {
5
5
  "dev": "blocklet dev",
6
6
  "eject": "vite eject",
@@ -103,7 +103,7 @@
103
103
  "@abtnode/types": "1.16.17",
104
104
  "@arcblock/eslint-config": "^0.2.4",
105
105
  "@arcblock/eslint-config-ts": "^0.2.4",
106
- "@did-pay/types": "1.13.40",
106
+ "@did-pay/types": "1.13.41",
107
107
  "@types/cookie-parser": "^1.4.5",
108
108
  "@types/cors": "^2.8.15",
109
109
  "@types/dotenv-flow": "^3.3.2",
@@ -140,5 +140,5 @@
140
140
  "parser": "typescript"
141
141
  }
142
142
  },
143
- "gitHead": "e5059a405064e32980119b2656ec952d95b7723c"
143
+ "gitHead": "5f150269dbc497d19cc4d8422b03c67d29793cf2"
144
144
  }