|
3 | 3 | /** |
4 | 4 | * The listing this package publishes as, and the document it packages: |
5 | 5 | * `objectstack.manifest.json` parses against the spec's own schema for that |
6 | | - * file and names the same package id as the stack; the README's credentials |
| 6 | + * file, names the same package id as the stack and points at the icon the |
| 7 | + * package owns (a public http(s) `iconUrl`); the README's credentials |
7 | 8 | * section names every credential the app's connectors reference (the |
8 | 9 | * marketplace handbook's "every credential it needs" rule, checked against |
9 | 10 | * the metadata rather than trusted); and the packaged OpenAPI document is the |
|
13 | 14 |
|
14 | 15 | import { describe, it, expect } from 'vitest'; |
15 | 16 | import { createHash } from 'node:crypto'; |
16 | | -import { readFileSync, existsSync } from 'node:fs'; |
| 17 | +import { readFileSync, existsSync, statSync } from 'node:fs'; |
17 | 18 | import { fileURLToPath } from 'node:url'; |
18 | 19 | import { TemplateManifestSchema } from '@objectstack/spec/marketplace'; |
19 | 20 | import stack from '../objectstack.config.js'; |
20 | 21 | import { STRIPE_READ_OPERATIONS, StripeConnector } from '../src/connectors/stripe.connector.js'; |
21 | 22 |
|
22 | 23 | const manifestPath = fileURLToPath(new URL('../objectstack.manifest.json', import.meta.url)); |
23 | 24 | const manifest = JSON.parse(readFileSync(manifestPath, 'utf8')) as Record<string, unknown>; |
| 25 | + |
| 26 | +/** Where the listing icon is served from once this package's tree is on `main`. */ |
| 27 | +const ICON_URL = 'https://raw.githubusercontent.com/objectstack-ai/objectstack/main/packages/apps/connector-stripe/assets/icon.svg'; |
| 28 | + |
| 29 | +/** |
| 30 | + * Why a manifest's `iconUrl` cannot be the listing icon, or `null` when it can: |
| 31 | + * `os package publish` sends the key as the package's `icon_url`, and the |
| 32 | + * marketplace handbook asks for a public http(s) URL. `TemplateManifestSchema` |
| 33 | + * accepts any URL scheme, so the scheme is checked here. |
| 34 | + */ |
| 35 | +function iconUrlProblem(m: Record<string, unknown>): string | null { |
| 36 | + const value = m.iconUrl; |
| 37 | + if (typeof value !== 'string') return 'iconUrl is absent'; |
| 38 | + let url: URL; |
| 39 | + try { |
| 40 | + url = new URL(value); |
| 41 | + } catch { |
| 42 | + return `iconUrl is not a URL: ${value}`; |
| 43 | + } |
| 44 | + return url.protocol === 'https:' || url.protocol === 'http:' ? null : `iconUrl is not http(s): ${value}`; |
| 45 | +} |
24 | 46 | const readme = readFileSync(fileURLToPath(new URL('../README.md', import.meta.url)), 'utf8'); |
25 | 47 | const documentBytes = readFileSync(fileURLToPath(new URL('../openapi/stripe.openapi.json', import.meta.url))); |
26 | 48 | const document = JSON.parse(documentBytes.toString('utf8')) as { |
@@ -65,6 +87,27 @@ describe('connector-stripe listing', () => { |
65 | 87 | expect(credentials).toContain('https://dashboard.stripe.com/apikeys'); |
66 | 88 | }); |
67 | 89 |
|
| 90 | + it('carries a public http(s) iconUrl', () => { |
| 91 | + expect(iconUrlProblem(manifest)).toBeNull(); |
| 92 | + }); |
| 93 | + |
| 94 | + it('refuses an iconUrl that is absent or not http(s)', () => { |
| 95 | + const withoutIcon = { ...manifest }; |
| 96 | + delete withoutIcon.iconUrl; |
| 97 | + expect(iconUrlProblem(withoutIcon)).toBe('iconUrl is absent'); |
| 98 | + expect(iconUrlProblem({ ...manifest, iconUrl: 'ftp://example.com/icon.svg' })).toMatch(/not http\(s\)/); |
| 99 | + expect(iconUrlProblem({ ...manifest, iconUrl: 'assets/icon.svg' })).toMatch(/not a URL/); |
| 100 | + }); |
| 101 | + |
| 102 | + it('points iconUrl at the icon this package owns', () => { |
| 103 | + expect(manifest.iconUrl).toBe(ICON_URL); |
| 104 | + const iconPath = fileURLToPath(new URL('../assets/icon.svg', import.meta.url)); |
| 105 | + expect(existsSync(iconPath)).toBe(true); |
| 106 | + // `--icon-file` takes up to 256 KB; hold the owned asset to the same bound. |
| 107 | + expect(statSync(iconPath).size).toBeLessThan(256 * 1024); |
| 108 | + expect(readFileSync(iconPath, 'utf8')).toMatch(/^<svg [^>]*viewBox="0 0 256 256"/); |
| 109 | + }); |
| 110 | + |
68 | 111 | it('carries no secret in metadata', () => { |
69 | 112 | for (const c of stack.connectors ?? []) { |
70 | 113 | expect(c).not.toHaveProperty('authentication.token'); |
|
0 commit comments