@open-mercato/sync-shopify 0.11.1-develop.9114.1.e26ee64834 → 0.11.1-develop.9121.1.1b6d34f5d8

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,6 @@
1
+ import {
2
+ inspectStoredCredentials
3
+ } from "@open-mercato/core/modules/integrations/lib/credentials-service";
1
4
  import { resolveApiVersion } from "./client.js";
2
5
  import { SHOPIFY_INTEGRATION_ID } from "./types.js";
3
6
  function readEnvValue(env, key) {
@@ -24,10 +27,20 @@ async function applyShopifyEnvPreset(params) {
24
27
  return { status: "skipped", reason: "No Shopify preset env variables were provided." };
25
28
  }
26
29
  const force = params.force ?? preset.force;
27
- const existing = await params.credentialsService.getRaw(SHOPIFY_INTEGRATION_ID, params.scope);
28
- if (!force && existing) {
30
+ const existing = await inspectStoredCredentials(
31
+ params.credentialsService,
32
+ SHOPIFY_INTEGRATION_ID,
33
+ params.scope,
34
+ { via: "getRaw" }
35
+ );
36
+ if (!force && existing.state !== "absent") {
29
37
  return { status: "skipped", reason: "Shopify credentials already exist. Use force to overwrite them." };
30
38
  }
39
+ if (existing.state === "undecryptable") {
40
+ throw new Error(
41
+ `[internal] The stored ${SHOPIFY_INTEGRATION_ID} credentials cannot be opened with any available encryption key; the preset does not overwrite them. Re-enter them in the integration settings.`
42
+ );
43
+ }
31
44
  await params.credentialsService.save(SHOPIFY_INTEGRATION_ID, {
32
45
  shopDomain: preset.shopDomain,
33
46
  clientId: preset.clientId,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/modules/sync_shopify/lib/preset.ts"],
4
- "sourcesContent": ["import type { CredentialsService } from '@open-mercato/core/modules/integrations/lib/credentials-service'\nimport type { IntegrationLogService } from '@open-mercato/core/modules/integrations/lib/log-service'\nimport type { IntegrationStateService } from '@open-mercato/core/modules/integrations/lib/state-service'\nimport { resolveApiVersion } from './client'\nimport { SHOPIFY_INTEGRATION_ID } from './types'\n\ntype IntegrationScope = {\n organizationId: string\n tenantId: string\n}\n\nexport type ShopifyEnvPreset = {\n shopDomain: string\n clientId: string\n clientSecret: string\n apiVersion: string\n force: boolean\n}\n\nexport type ApplyShopifyPresetResult =\n | { status: 'skipped'; reason: string }\n | { status: 'configured' }\n\nfunction readEnvValue(env: NodeJS.ProcessEnv, key: string): string | undefined {\n const value = env[key]?.trim()\n return value ? value : undefined\n}\n\nexport function readShopifyEnvPreset(env: NodeJS.ProcessEnv = process.env): ShopifyEnvPreset | null {\n const shopDomain = readEnvValue(env, 'OM_INTEGRATION_SHOPIFY_SHOP_DOMAIN')\n const clientId = readEnvValue(env, 'OM_INTEGRATION_SHOPIFY_CLIENT_ID')\n const clientSecret = readEnvValue(env, 'OM_INTEGRATION_SHOPIFY_CLIENT_SECRET')\n if (!shopDomain || !clientId || !clientSecret) return null\n const force = env.OM_INTEGRATION_SHOPIFY_FORCE === 'true' || env.OM_INTEGRATION_SHOPIFY_FORCE === '1'\n return {\n shopDomain,\n clientId,\n clientSecret,\n apiVersion: resolveApiVersion(readEnvValue(env, 'OM_INTEGRATION_SHOPIFY_API_VERSION')),\n force,\n }\n}\n\nexport async function applyShopifyEnvPreset(params: {\n credentialsService: CredentialsService\n integrationStateService: IntegrationStateService\n integrationLogService?: IntegrationLogService\n scope: IntegrationScope\n force?: boolean\n env?: NodeJS.ProcessEnv\n}): Promise<ApplyShopifyPresetResult> {\n const preset = readShopifyEnvPreset(params.env)\n if (!preset) {\n return { status: 'skipped', reason: 'No Shopify preset env variables were provided.' }\n }\n const force = params.force ?? preset.force\n const existing = await params.credentialsService.getRaw(SHOPIFY_INTEGRATION_ID, params.scope)\n if (!force && existing) {\n return { status: 'skipped', reason: 'Shopify credentials already exist. Use force to overwrite them.' }\n }\n await params.credentialsService.save(SHOPIFY_INTEGRATION_ID, {\n shopDomain: preset.shopDomain,\n clientId: preset.clientId,\n clientSecret: preset.clientSecret,\n apiVersion: preset.apiVersion,\n }, params.scope)\n await params.integrationStateService.upsert(SHOPIFY_INTEGRATION_ID, { isEnabled: true }, params.scope)\n if (params.integrationLogService) {\n await params.integrationLogService.scoped(SHOPIFY_INTEGRATION_ID, params.scope).info(\n 'Shopify integration was preconfigured from environment variables.',\n { shopDomain: preset.shopDomain, apiVersion: preset.apiVersion },\n )\n }\n return { status: 'configured' }\n}\n"],
5
- "mappings": "AAGA,SAAS,yBAAyB;AAClC,SAAS,8BAA8B;AAmBvC,SAAS,aAAa,KAAwB,KAAiC;AAC7E,QAAM,QAAQ,IAAI,GAAG,GAAG,KAAK;AAC7B,SAAO,QAAQ,QAAQ;AACzB;AAEO,SAAS,qBAAqB,MAAyB,QAAQ,KAA8B;AAClG,QAAM,aAAa,aAAa,KAAK,oCAAoC;AACzE,QAAM,WAAW,aAAa,KAAK,kCAAkC;AACrE,QAAM,eAAe,aAAa,KAAK,sCAAsC;AAC7E,MAAI,CAAC,cAAc,CAAC,YAAY,CAAC,aAAc,QAAO;AACtD,QAAM,QAAQ,IAAI,iCAAiC,UAAU,IAAI,iCAAiC;AAClG,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,YAAY,kBAAkB,aAAa,KAAK,oCAAoC,CAAC;AAAA,IACrF;AAAA,EACF;AACF;AAEA,eAAsB,sBAAsB,QAON;AACpC,QAAM,SAAS,qBAAqB,OAAO,GAAG;AAC9C,MAAI,CAAC,QAAQ;AACX,WAAO,EAAE,QAAQ,WAAW,QAAQ,iDAAiD;AAAA,EACvF;AACA,QAAM,QAAQ,OAAO,SAAS,OAAO;AACrC,QAAM,WAAW,MAAM,OAAO,mBAAmB,OAAO,wBAAwB,OAAO,KAAK;AAC5F,MAAI,CAAC,SAAS,UAAU;AACtB,WAAO,EAAE,QAAQ,WAAW,QAAQ,kEAAkE;AAAA,EACxG;AACA,QAAM,OAAO,mBAAmB,KAAK,wBAAwB;AAAA,IAC3D,YAAY,OAAO;AAAA,IACnB,UAAU,OAAO;AAAA,IACjB,cAAc,OAAO;AAAA,IACrB,YAAY,OAAO;AAAA,EACrB,GAAG,OAAO,KAAK;AACf,QAAM,OAAO,wBAAwB,OAAO,wBAAwB,EAAE,WAAW,KAAK,GAAG,OAAO,KAAK;AACrG,MAAI,OAAO,uBAAuB;AAChC,UAAM,OAAO,sBAAsB,OAAO,wBAAwB,OAAO,KAAK,EAAE;AAAA,MAC9E;AAAA,MACA,EAAE,YAAY,OAAO,YAAY,YAAY,OAAO,WAAW;AAAA,IACjE;AAAA,EACF;AACA,SAAO,EAAE,QAAQ,aAAa;AAChC;",
4
+ "sourcesContent": ["import {\n inspectStoredCredentials,\n type CredentialsService,\n} from '@open-mercato/core/modules/integrations/lib/credentials-service'\nimport type { IntegrationLogService } from '@open-mercato/core/modules/integrations/lib/log-service'\nimport type { IntegrationStateService } from '@open-mercato/core/modules/integrations/lib/state-service'\nimport { resolveApiVersion } from './client'\nimport { SHOPIFY_INTEGRATION_ID } from './types'\n\ntype IntegrationScope = {\n organizationId: string\n tenantId: string\n}\n\nexport type ShopifyEnvPreset = {\n shopDomain: string\n clientId: string\n clientSecret: string\n apiVersion: string\n force: boolean\n}\n\nexport type ApplyShopifyPresetResult =\n | { status: 'skipped'; reason: string }\n | { status: 'configured' }\n\nfunction readEnvValue(env: NodeJS.ProcessEnv, key: string): string | undefined {\n const value = env[key]?.trim()\n return value ? value : undefined\n}\n\nexport function readShopifyEnvPreset(env: NodeJS.ProcessEnv = process.env): ShopifyEnvPreset | null {\n const shopDomain = readEnvValue(env, 'OM_INTEGRATION_SHOPIFY_SHOP_DOMAIN')\n const clientId = readEnvValue(env, 'OM_INTEGRATION_SHOPIFY_CLIENT_ID')\n const clientSecret = readEnvValue(env, 'OM_INTEGRATION_SHOPIFY_CLIENT_SECRET')\n if (!shopDomain || !clientId || !clientSecret) return null\n const force = env.OM_INTEGRATION_SHOPIFY_FORCE === 'true' || env.OM_INTEGRATION_SHOPIFY_FORCE === '1'\n return {\n shopDomain,\n clientId,\n clientSecret,\n apiVersion: resolveApiVersion(readEnvValue(env, 'OM_INTEGRATION_SHOPIFY_API_VERSION')),\n force,\n }\n}\n\nexport async function applyShopifyEnvPreset(params: {\n credentialsService: CredentialsService\n integrationStateService: IntegrationStateService\n integrationLogService?: IntegrationLogService\n scope: IntegrationScope\n force?: boolean\n env?: NodeJS.ProcessEnv\n}): Promise<ApplyShopifyPresetResult> {\n const preset = readShopifyEnvPreset(params.env)\n if (!preset) {\n return { status: 'skipped', reason: 'No Shopify preset env variables were provided.' }\n }\n const force = params.force ?? preset.force\n const existing = await inspectStoredCredentials(\n params.credentialsService,\n SHOPIFY_INTEGRATION_ID,\n params.scope,\n { via: 'getRaw' },\n )\n if (!force && existing.state !== 'absent') {\n return { status: 'skipped', reason: 'Shopify credentials already exist. Use force to overwrite them.' }\n }\n if (existing.state === 'undecryptable') {\n throw new Error(\n `[internal] The stored ${SHOPIFY_INTEGRATION_ID} credentials cannot be opened with any available encryption key; `\n + 'the preset does not overwrite them. Re-enter them in the integration settings.',\n )\n }\n await params.credentialsService.save(SHOPIFY_INTEGRATION_ID, {\n shopDomain: preset.shopDomain,\n clientId: preset.clientId,\n clientSecret: preset.clientSecret,\n apiVersion: preset.apiVersion,\n }, params.scope)\n await params.integrationStateService.upsert(SHOPIFY_INTEGRATION_ID, { isEnabled: true }, params.scope)\n if (params.integrationLogService) {\n await params.integrationLogService.scoped(SHOPIFY_INTEGRATION_ID, params.scope).info(\n 'Shopify integration was preconfigured from environment variables.',\n { shopDomain: preset.shopDomain, apiVersion: preset.apiVersion },\n )\n }\n return { status: 'configured' }\n}\n"],
5
+ "mappings": "AAAA;AAAA,EACE;AAAA,OAEK;AAGP,SAAS,yBAAyB;AAClC,SAAS,8BAA8B;AAmBvC,SAAS,aAAa,KAAwB,KAAiC;AAC7E,QAAM,QAAQ,IAAI,GAAG,GAAG,KAAK;AAC7B,SAAO,QAAQ,QAAQ;AACzB;AAEO,SAAS,qBAAqB,MAAyB,QAAQ,KAA8B;AAClG,QAAM,a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,IACjE;AAAA,EACF;AACA,SAAO,EAAE,QAAQ,aAAa;AAChC;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-mercato/sync-shopify",
3
- "version": "0.11.1-develop.9114.1.e26ee64834",
3
+ "version": "0.11.1-develop.9121.1.1b6d34f5d8",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -37,18 +37,18 @@
37
37
  }
38
38
  },
39
39
  "dependencies": {
40
- "@open-mercato/core": "0.11.1-develop.9114.1.e26ee64834"
40
+ "@open-mercato/core": "0.11.1-develop.9121.1.1b6d34f5d8"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "@mikro-orm/postgresql": "^7.0.14",
44
- "@open-mercato/ai-assistant": "0.11.1-develop.9114.1.e26ee64834",
45
- "@open-mercato/shared": "0.11.1-develop.9114.1.e26ee64834",
46
- "@open-mercato/ui": "0.11.1-develop.9114.1.e26ee64834",
44
+ "@open-mercato/ai-assistant": "0.11.1-develop.9121.1.1b6d34f5d8",
45
+ "@open-mercato/shared": "0.11.1-develop.9121.1.1b6d34f5d8",
46
+ "@open-mercato/ui": "0.11.1-develop.9121.1.1b6d34f5d8",
47
47
  "react": "^19.0.0",
48
48
  "react-dom": "^19.0.0"
49
49
  },
50
50
  "devDependencies": {
51
- "@open-mercato/shared": "0.11.1-develop.9114.1.e26ee64834",
51
+ "@open-mercato/shared": "0.11.1-develop.9121.1.1b6d34f5d8",
52
52
  "@types/jest": "^30.0.0",
53
53
  "esbuild": "^0.28.2",
54
54
  "glob": "^14.0.6",
@@ -1,4 +1,9 @@
1
- import { readShopifyEnvPreset } from '../lib/preset'
1
+ import {
2
+ CredentialsEncryptionUnavailableError,
3
+ type CredentialsService,
4
+ } from '@open-mercato/core/modules/integrations/lib/credentials-service'
5
+ import type { IntegrationStateService } from '@open-mercato/core/modules/integrations/lib/state-service'
6
+ import { applyShopifyEnvPreset, readShopifyEnvPreset } from '../lib/preset'
2
7
 
3
8
  describe('readShopifyEnvPreset', () => {
4
9
  it('returns null until both required variables are set', () => {
@@ -16,3 +21,38 @@ describe('readShopifyEnvPreset', () => {
16
21
  })
17
22
  })
18
23
  })
24
+
25
+ describe('applyShopifyEnvPreset over credentials no key opens (D19)', () => {
26
+ const env = {
27
+ OM_INTEGRATION_SHOPIFY_SHOP_DOMAIN: 'demo.myshopify.com',
28
+ OM_INTEGRATION_SHOPIFY_CLIENT_ID: 'client-id',
29
+ OM_INTEGRATION_SHOPIFY_CLIENT_SECRET: 'client-secret',
30
+ }
31
+ const scope = { tenantId: 'tenant-1', organizationId: 'org-1' }
32
+
33
+ function services() {
34
+ const save = jest.fn(async () => undefined)
35
+ const getRaw = jest.fn().mockRejectedValue(new CredentialsEncryptionUnavailableError('tenant-1', 'undecryptable'))
36
+ return {
37
+ save,
38
+ credentialsService: { getRaw, save } as unknown as CredentialsService,
39
+ integrationStateService: { upsert: jest.fn(async () => undefined) } as unknown as IntegrationStateService,
40
+ }
41
+ }
42
+
43
+ it('skips without force and leaves the blob unchanged', async () => {
44
+ const { save, credentialsService, integrationStateService } = services()
45
+
46
+ await expect(applyShopifyEnvPreset({ credentialsService, integrationStateService, scope, env }))
47
+ .resolves.toMatchObject({ status: 'skipped' })
48
+ expect(save).not.toHaveBeenCalled()
49
+ })
50
+
51
+ it('fails under force with a message naming the integration instead of saving', async () => {
52
+ const { save, credentialsService, integrationStateService } = services()
53
+
54
+ await expect(applyShopifyEnvPreset({ credentialsService, integrationStateService, scope, env, force: true }))
55
+ .rejects.toThrow(/^\[internal\] The stored sync_shopify credentials cannot be opened/)
56
+ expect(save).not.toHaveBeenCalled()
57
+ })
58
+ })
@@ -1,4 +1,7 @@
1
- import type { CredentialsService } from '@open-mercato/core/modules/integrations/lib/credentials-service'
1
+ import {
2
+ inspectStoredCredentials,
3
+ type CredentialsService,
4
+ } from '@open-mercato/core/modules/integrations/lib/credentials-service'
2
5
  import type { IntegrationLogService } from '@open-mercato/core/modules/integrations/lib/log-service'
3
6
  import type { IntegrationStateService } from '@open-mercato/core/modules/integrations/lib/state-service'
4
7
  import { resolveApiVersion } from './client'
@@ -54,10 +57,21 @@ export async function applyShopifyEnvPreset(params: {
54
57
  return { status: 'skipped', reason: 'No Shopify preset env variables were provided.' }
55
58
  }
56
59
  const force = params.force ?? preset.force
57
- const existing = await params.credentialsService.getRaw(SHOPIFY_INTEGRATION_ID, params.scope)
58
- if (!force && existing) {
60
+ const existing = await inspectStoredCredentials(
61
+ params.credentialsService,
62
+ SHOPIFY_INTEGRATION_ID,
63
+ params.scope,
64
+ { via: 'getRaw' },
65
+ )
66
+ if (!force && existing.state !== 'absent') {
59
67
  return { status: 'skipped', reason: 'Shopify credentials already exist. Use force to overwrite them.' }
60
68
  }
69
+ if (existing.state === 'undecryptable') {
70
+ throw new Error(
71
+ `[internal] The stored ${SHOPIFY_INTEGRATION_ID} credentials cannot be opened with any available encryption key; `
72
+ + 'the preset does not overwrite them. Re-enter them in the integration settings.',
73
+ )
74
+ }
61
75
  await params.credentialsService.save(SHOPIFY_INTEGRATION_ID, {
62
76
  shopDomain: preset.shopDomain,
63
77
  clientId: preset.clientId,