@commercetools/cli-topic-integration-layer 0.2.1 → 0.3.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 (54) hide show
  1. package/README.md +1 -0
  2. package/dist/commands/integration-layer/explore.d.ts +20 -0
  3. package/dist/commands/integration-layer/explore.js +209 -0
  4. package/dist/commands/integration-layer/explore.js.map +1 -0
  5. package/dist/commands/integration-layer/extension/build.d.ts +2 -0
  6. package/dist/commands/integration-layer/extension/build.js +24 -3
  7. package/dist/commands/integration-layer/extension/build.js.map +1 -1
  8. package/dist/commands/integration-layer/extension/invoke.d.ts +1 -0
  9. package/dist/commands/integration-layer/extension/invoke.js +9 -4
  10. package/dist/commands/integration-layer/extension/invoke.js.map +1 -1
  11. package/dist/commands/integration-layer/extension/push.d.ts +15 -0
  12. package/dist/commands/integration-layer/extension/push.js +137 -3
  13. package/dist/commands/integration-layer/extension/push.js.map +1 -1
  14. package/dist/commands/integration-layer/extension/serve.d.ts +30 -0
  15. package/dist/commands/integration-layer/extension/serve.js +244 -6
  16. package/dist/commands/integration-layer/extension/serve.js.map +1 -1
  17. package/dist/commands/integration-layer/extension/status.js +4 -0
  18. package/dist/commands/integration-layer/extension/status.js.map +1 -1
  19. package/dist/commands/integration-layer/extension/validate.d.ts +2 -0
  20. package/dist/commands/integration-layer/extension/validate.js +24 -2
  21. package/dist/commands/integration-layer/extension/validate.js.map +1 -1
  22. package/dist/commands/integration-layer/init.js +228 -77
  23. package/dist/commands/integration-layer/init.js.map +1 -1
  24. package/dist/lib/awaitBundleState.d.ts +33 -0
  25. package/dist/lib/awaitBundleState.js +77 -0
  26. package/dist/lib/awaitBundleState.js.map +1 -0
  27. package/dist/lib/base.d.ts +35 -0
  28. package/dist/lib/base.js +99 -13
  29. package/dist/lib/base.js.map +1 -1
  30. package/dist/lib/ilClient.d.ts +62 -2
  31. package/dist/lib/ilClient.js +42 -2
  32. package/dist/lib/ilClient.js.map +1 -1
  33. package/dist/lib/sourceRevision.d.ts +39 -0
  34. package/dist/lib/sourceRevision.js +95 -0
  35. package/dist/lib/sourceRevision.js.map +1 -0
  36. package/dist/lib/tooling/exploreSchema.d.ts +15 -0
  37. package/dist/lib/tooling/exploreSchema.js +77 -0
  38. package/dist/lib/tooling/exploreSchema.js.map +1 -0
  39. package/dist/lib/tooling/explorerPage.d.ts +1 -0
  40. package/dist/lib/tooling/explorerPage.js +96 -0
  41. package/dist/lib/tooling/explorerPage.js.map +1 -0
  42. package/dist/lib/tooling/explorerServer.d.ts +27 -0
  43. package/dist/lib/tooling/explorerServer.js +134 -0
  44. package/dist/lib/tooling/explorerServer.js.map +1 -0
  45. package/dist/lib/tooling/extensions.d.ts +77 -0
  46. package/dist/lib/tooling/extensions.js +209 -0
  47. package/dist/lib/tooling/extensions.js.map +1 -0
  48. package/dist/lib/tooling/introspectionRequest.d.ts +13 -0
  49. package/dist/lib/tooling/introspectionRequest.js +47 -0
  50. package/dist/lib/tooling/introspectionRequest.js.map +1 -0
  51. package/dist/lib/tooling/session.d.ts +36 -0
  52. package/dist/lib/tooling/session.js +99 -0
  53. package/dist/lib/tooling/session.js.map +1 -0
  54. package/package.json +10 -12
@@ -0,0 +1,36 @@
1
+ /** Which identity the explorer's proxy runs operations as. */
2
+ export type SessionGrant = {
3
+ kind: "anonymous";
4
+ } | {
5
+ kind: "password";
6
+ email: string;
7
+ password: string;
8
+ };
9
+ /**
10
+ * An explicit presentment selection, as a storefront's locale/currency switcher
11
+ * would send it. Every field is optional and independently defaulted by the
12
+ * integration layer from the project config, so `{ currency: "EUR" }` alone is
13
+ * valid — it changes the currency and leaves locale and country at the project's.
14
+ */
15
+ export interface Presentment {
16
+ locale?: string;
17
+ currency?: string;
18
+ country?: string;
19
+ }
20
+ /** A minted session, plus human labels for the startup banner. */
21
+ export interface MintedSession {
22
+ token: string;
23
+ /** e.g. `anonymous` or `customer alice@example.com` — printed, never logged elsewhere. */
24
+ describe: string;
25
+ /** e.g. `de-DE / EUR / DE` or `project defaults` — what prices will be shown in. */
26
+ presentment: string;
27
+ }
28
+ /**
29
+ * Mint an integration-layer session bearer at `POST <authUrl>/<project>/session`.
30
+ *
31
+ * `authUrl` is the identity edge (the storefront pod), NOT the extensions edge that
32
+ * serves the manage-surface routes — in the deployed topology those are different
33
+ * hosts (`auth.…` vs `extensions.…`), which is why the explorer resolves them
34
+ * separately.
35
+ */
36
+ export declare function mintSession(authUrl: string, projectKey: string, grant: SessionGrant, presentment?: Presentment): Promise<MintedSession>;
@@ -0,0 +1,99 @@
1
+ // Session bearers for the local explorer's proxy.
2
+ //
3
+ // The explorer runs operations against the DEPLOYED edge, so it needs the same
4
+ // credential a storefront would carry: an integration-layer session bearer, minted
5
+ // through the ordinary `POST /<project>/session` endpoint.
6
+ //
7
+ // There is deliberately NO privileged/debug path here. The two grants below are the
8
+ // two a real storefront uses — anonymous, and a customer logging in with their own
9
+ // email and password. The retired operator console had an `x-il-act-as`
10
+ // impersonation bar that ran under the project's service-account credentials; that
11
+ // is exactly what this does not reimplement. If you want to explore as a customer,
12
+ // you log in as that customer.
13
+ //
14
+ // PRESENTMENT (locale / currency / country) rides the same mint call. The GraphQL
15
+ // boundary reads all three straight off the session and FAILS the request if any is
16
+ // missing — there is no `?? "en-US"` downstream — so a session is only ever minted
17
+ // with them resolved. Mint is the one place they can be chosen: the integration
18
+ // layer applies its own project-configured defaults when we send none, exactly as
19
+ // it does for a storefront that has no locale switcher. Passing them here is
20
+ // therefore the storefront's own flow, not a debug override.
21
+ /**
22
+ * Mint an integration-layer session bearer at `POST <authUrl>/<project>/session`.
23
+ *
24
+ * `authUrl` is the identity edge (the storefront pod), NOT the extensions edge that
25
+ * serves the manage-surface routes — in the deployed topology those are different
26
+ * hosts (`auth.…` vs `extensions.…`), which is why the explorer resolves them
27
+ * separately.
28
+ */
29
+ export async function mintSession(authUrl, projectKey, grant, presentment = {}) {
30
+ const base = authUrl.replace(/\/+$/, "");
31
+ const url = `${base}/${encodeURIComponent(projectKey)}/session`;
32
+ const identity = grant.kind === "anonymous"
33
+ ? { grant_type: "anonymous" }
34
+ : { grant_type: "password", email: grant.email, password: grant.password };
35
+ // Currency and country are upper-cased to the canonical form the session will
36
+ // hold (the integration layer upper-cases them too, so `--currency eur` already
37
+ // worked) — done here so the banner reports the value the session actually got
38
+ // rather than echoing back what was typed. Locale keeps its case: `de-DE` is not
39
+ // `DE-DE`.
40
+ const chosen = {
41
+ locale: presentment.locale,
42
+ currency: presentment.currency?.toUpperCase(),
43
+ country: presentment.country?.toUpperCase(),
44
+ };
45
+ // Only send what was actually chosen: an absent key means "use the project's
46
+ // default", which is a different instruction to sending an empty string.
47
+ const body = {
48
+ ...identity,
49
+ ...(chosen.locale === undefined ? {} : { locale: chosen.locale }),
50
+ ...(chosen.currency === undefined ? {} : { currency: chosen.currency }),
51
+ ...(chosen.country === undefined ? {} : { country: chosen.country }),
52
+ };
53
+ const res = await fetch(url, {
54
+ method: "POST",
55
+ headers: { "content-type": "application/json" },
56
+ body: JSON.stringify(body),
57
+ });
58
+ const text = await res.text();
59
+ if (!res.ok) {
60
+ // Surface the integration layer's own error (an OAuth-shaped
61
+ // `{ error, error_description }`) rather than a bare status — a bad password
62
+ // and an unreachable edge should not read the same.
63
+ let detail = text;
64
+ try {
65
+ const parsed = JSON.parse(text);
66
+ detail = parsed.error_description ?? parsed.error ?? text;
67
+ }
68
+ catch {
69
+ // not JSON — use the raw body
70
+ }
71
+ const who = grant.kind === "anonymous" ? "an anonymous session" : `a session for ${grant.email}`;
72
+ throw new Error(`could not mint ${who} (${res.status}) at ${url}: ${detail}`);
73
+ }
74
+ const token = JSON.parse(text).token;
75
+ if (!token)
76
+ throw new Error(`session response from ${url} had no \`token\``);
77
+ return {
78
+ token,
79
+ describe: grant.kind === "anonymous" ? "anonymous" : `customer ${grant.email}`,
80
+ presentment: describePresentment(chosen),
81
+ };
82
+ }
83
+ /**
84
+ * What the banner says prices will be shown in. Reports what was REQUESTED, marking
85
+ * the rest as the project's — the mint response carries the token only, so claiming
86
+ * a concrete value we did not choose would mean decoding the session JWT and
87
+ * depending on its internal shape.
88
+ */
89
+ function describePresentment(p) {
90
+ const parts = [
91
+ p.locale ?? "project locale",
92
+ p.currency ?? "project currency",
93
+ p.country ?? "project country",
94
+ ];
95
+ if (!p.locale && !p.currency && !p.country)
96
+ return "project defaults";
97
+ return parts.join(" / ");
98
+ }
99
+ //# sourceMappingURL=session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.js","sourceRoot":"","sources":["../../../src/lib/tooling/session.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,EAAE;AACF,+EAA+E;AAC/E,mFAAmF;AACnF,2DAA2D;AAC3D,EAAE;AACF,oFAAoF;AACpF,mFAAmF;AACnF,wEAAwE;AACxE,mFAAmF;AACnF,mFAAmF;AACnF,+BAA+B;AAC/B,EAAE;AACF,kFAAkF;AAClF,oFAAoF;AACpF,mFAAmF;AACnF,gFAAgF;AAChF,kFAAkF;AAClF,6EAA6E;AAC7E,6DAA6D;AA4B7D;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,OAAe,EACf,UAAkB,EAClB,KAAmB,EACnB,cAA2B,EAAE;IAE7B,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACzC,MAAM,GAAG,GAAG,GAAG,IAAI,IAAI,kBAAkB,CAAC,UAAU,CAAC,UAAU,CAAC;IAChE,MAAM,QAAQ,GACZ,KAAK,CAAC,IAAI,KAAK,WAAW;QACxB,CAAC,CAAC,EAAE,UAAU,EAAE,WAAW,EAAE;QAC7B,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC;IAC/E,8EAA8E;IAC9E,gFAAgF;IAChF,+EAA+E;IAC/E,iFAAiF;IACjF,WAAW;IACX,MAAM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AAC;QAC5D,CAAC;QAAC,MAAM,CAAC;YACP,8BAA8B;QAChC,CAAC;QACD,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,iBAAiB,KAAK,CAAC,KAAK,EAAE,CAAC;QACjG,MAAM,IAAI,KAAK,CAAC,kBAAkB,GAAG,KAAK,GAAG,CAAC,MAAM,QAAQ,GAAG,KAAK,MAAM,EAAE,CAAC,CAAC;IAChF,CAAC;IAED,MAAM,KAAK,GAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAwB,CAAC,KAAK,CAAC;IAC7D,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,yBAAyB,GAAG,mBAAmB,CAAC,CAAC;IAE7E,OAAO;QACL,KAAK;QACL,QAAQ,EAAE,KAAK,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,YAAY,KAAK,CAAC,KAAK,EAAE;QAC9E,WAAW,EAAE,mBAAmB,CAAC,MAAM,CAAC;KACzC,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAS,mBAAmB,CAAC,CAAc;IACzC,MAAM,KAAK,GAAG;QACZ,CAAC,CAAC,MAAM,IAAI,gBAAgB;QAC5B,CAAC,CAAC,QAAQ,IAAI,kBAAkB;QAChC,CAAC,CAAC,OAAO,IAAI,iBAAiB;KAC/B,CAAC;IACF,IAAI,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,CAAC,OAAO;QAAE,OAAO,kBAAkB,CAAC;IACtE,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC3B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercetools/cli-topic-integration-layer",
3
- "version": "0.2.1",
3
+ "version": "0.3.1",
4
4
  "description": "commercetools CLI plugin: integration-layer topic",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -14,28 +14,20 @@
14
14
  "access": "public",
15
15
  "registry": "https://registry.npmjs.org/"
16
16
  },
17
- "scripts": {
18
- "clean": "rimraf dist",
19
- "build": "pnpm clean && tsc -p tsconfig.build.json",
20
- "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json",
21
- "test": "vitest run --disable-console-intercept"
22
- },
23
17
  "dependencies": {
18
+ "@commercetools/cli-plugin-auth": ">=0.0.6",
24
19
  "@apollo/composition": "^2.14.1",
25
20
  "@apollo/gateway": "^2.14.1",
26
21
  "@apollo/subgraph": "^2.14.1",
27
22
  "@envelop/apollo-federation": "^8.1.1",
23
+ "@graphql-tools/merge": "^9.2.2",
28
24
  "@oclif/core": "4.2.10",
29
25
  "esbuild": "^0.28.0",
30
26
  "graphql": "^16.9.0",
31
27
  "graphql-yoga": "^5.21.2",
32
28
  "typescript": "^5.7.2"
33
29
  },
34
- "peerDependencies": {
35
- "@commercetools/cli-plugin-auth": ">=0.0.6"
36
- },
37
30
  "devDependencies": {
38
- "@commercetools/cli-plugin-auth": "0.0.6",
39
31
  "@commercetools/platform-sdk": "8.25.0",
40
32
  "@oclif/test": "^4.1.12",
41
33
  "@types/node": "^22.10.2",
@@ -45,5 +37,11 @@
45
37
  "oclif": {
46
38
  "topicSeparator": " ",
47
39
  "commands": "./dist/commands"
40
+ },
41
+ "scripts": {
42
+ "clean": "rimraf dist",
43
+ "build": "pnpm clean && tsc -p tsconfig.build.json",
44
+ "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json",
45
+ "test": "vitest run --disable-console-intercept"
48
46
  }
49
- }
47
+ }