Skip to content

Commit

Permalink
Merge branch 'main' into PDE-4682-align-text
Browse files Browse the repository at this point in the history
  • Loading branch information
rnegron committed Feb 2, 2024
2 parents 069ed34 + b64e43f commit 9e9ece7
Show file tree
Hide file tree
Showing 13 changed files with 591 additions and 103 deletions.
1 change: 1 addition & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4175,6 +4175,7 @@ <h2 id="dehydration">Dehydration</h2>
</blockquote><p>The method <code>z.dehydrate(func, inputData)</code> has two required arguments:</p><ul>
<li><code>func</code> - the function to call to fetch the extra data. Can be any raw <code>function</code>, defined in the file doing the dehydration or imported from another part of your app. You must also register the function in the app&apos;s <code>hydrators</code> property. Note that since v10.1.0, the maximum payload size to pass to <code>z.dehydrate</code> / <code>z.dehydrateFile</code> is 6KB.</li>
<li><code>inputData</code> - this is an object that contains things like a <code>path</code> or <code>id</code> - whatever you need to load data on the other side</li>
<li>A known limitation of hydration is a 5 minute cache if the hydration call is made with identical <code>inputData</code> within that timeframe. To workaround this cache for records triggering hydration in close succession, include a unique value in the <code>inputData</code>, for example a <code>timestamp</code> in addition to the record <code>id</code>. </li>
</ul><blockquote>
<p><strong>Why do I need to register my functions?</strong> Because of how JavaScript works with its module system, we need an explicit handle on the function that can be accessed from the App definition without trying to &quot;automagically&quot; (and sometimes incorrectly) infer code locations.</p>
</blockquote><p>Here is an example that pulls in extra data for a movie:</p>
Expand Down
10 changes: 9 additions & 1 deletion example-apps/custom-auth/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,15 @@ module.exports = {

// Define any input app's auth requires here. The user will be prompted to enter
// this info when they connect their account.
fields: [{ key: 'apiKey', label: 'API Key', required: true }],
fields: [
{
key: 'apiKey',
label: 'API Key',
required: true,
helpText:
'Find the API Key in your [app settings page](https://yourapp.com/settings)',
},
],

// The test method allows Zapier to verify that the credentials a user provides
// are valid. We'll execute this method whenever a user connects their account for
Expand Down
1 change: 1 addition & 0 deletions packages/cli/README-source.md
Original file line number Diff line number Diff line change
Expand Up @@ -1421,6 +1421,7 @@ The method `z.dehydrate(func, inputData)` has two required arguments:
* `func` - the function to call to fetch the extra data. Can be any raw `function`, defined in the file doing the dehydration or imported from another part of your app. You must also register the function in the app's `hydrators` property. Note that since v10.1.0, the maximum payload size to pass to `z.dehydrate` / `z.dehydrateFile` is 6KB.
* `inputData` - this is an object that contains things like a `path` or `id` - whatever you need to load data on the other side
* A known limitation of hydration is a 5 minute cache if the hydration call is made with identical `inputData` within that timeframe. To workaround this cache for records triggering hydration in close succession, include a unique value in the `inputData`, for example a `timestamp` in addition to the record `id`.
> **Why do I need to register my functions?** Because of how JavaScript works with its module system, we need an explicit handle on the function that can be accessed from the App definition without trying to "automagically" (and sometimes incorrectly) infer code locations.
Expand Down
1 change: 1 addition & 0 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2573,6 +2573,7 @@ The method `z.dehydrate(func, inputData)` has two required arguments:
* `func` - the function to call to fetch the extra data. Can be any raw `function`, defined in the file doing the dehydration or imported from another part of your app. You must also register the function in the app's `hydrators` property. Note that since v10.1.0, the maximum payload size to pass to `z.dehydrate` / `z.dehydrateFile` is 6KB.
* `inputData` - this is an object that contains things like a `path` or `id` - whatever you need to load data on the other side
* A known limitation of hydration is a 5 minute cache if the hydration call is made with identical `inputData` within that timeframe. To workaround this cache for records triggering hydration in close succession, include a unique value in the `inputData`, for example a `timestamp` in addition to the record `id`.
> **Why do I need to register my functions?** Because of how JavaScript works with its module system, we need an explicit handle on the function that can be accessed from the App definition without trying to "automagically" (and sometimes incorrectly) infer code locations.
Expand Down
1 change: 1 addition & 0 deletions packages/cli/docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4175,6 +4175,7 @@ <h2 id="dehydration">Dehydration</h2>
</blockquote><p>The method <code>z.dehydrate(func, inputData)</code> has two required arguments:</p><ul>
<li><code>func</code> - the function to call to fetch the extra data. Can be any raw <code>function</code>, defined in the file doing the dehydration or imported from another part of your app. You must also register the function in the app&apos;s <code>hydrators</code> property. Note that since v10.1.0, the maximum payload size to pass to <code>z.dehydrate</code> / <code>z.dehydrateFile</code> is 6KB.</li>
<li><code>inputData</code> - this is an object that contains things like a <code>path</code> or <code>id</code> - whatever you need to load data on the other side</li>
<li>A known limitation of hydration is a 5 minute cache if the hydration call is made with identical <code>inputData</code> within that timeframe. To workaround this cache for records triggering hydration in close succession, include a unique value in the <code>inputData</code>, for example a <code>timestamp</code> in addition to the record <code>id</code>. </li>
</ul><blockquote>
<p><strong>Why do I need to register my functions?</strong> Because of how JavaScript works with its module system, we need an explicit handle on the function that can be accessed from the App definition without trying to &quot;automagically&quot; (and sometimes incorrectly) infer code locations.</p>
</blockquote><p>Here is an example that pulls in extra data for a movie:</p>
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"lint": "eslint src snippets",
"lint:fix": "eslint --fix src snippets",
"test": "cross-env NODE_ENV=test mocha -t 50s --recursive src/tests --exit",
"test-debug": "cross-env NODE_ENV=test node inspect ../../node_modules/.bin/mocha -t 50s --recursive src/tests --exit",
"smoke-test": "cross-env NODE_ENV=test mocha -t 2m --recursive src/smoke-tests --exit",
"validate-templates": "./scripts/validate-app-templates.js",
"set-template-versions": "./scripts/set-app-template-versions.js",
Expand Down Expand Up @@ -60,6 +61,7 @@
"lodash": "4.17.21",
"marked": "4.2.12",
"marked-terminal": "5.2.0",
"minimatch": "9.0.3",
"node-fetch": "2.6.7",
"ora": "5.4.0",
"parse-gitignore": "0.5.1",
Expand Down
208 changes: 207 additions & 1 deletion packages/cli/src/tests/utils/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ describe('build (runs slowly)', function () {
runCommand('npm', ['i'], { cwd: tmpDir });
// TODO: This test depends on how "typescript" example is set up, which
// isn't good. Should refactor not to rely on that.
runCommand('npm', ['run', 'build', '--scripts-prepend-node-path'], { cwd: tmpDir });
runCommand('npm', ['run', 'build', '--scripts-prepend-node-path'], {
cwd: tmpDir,
});
entryPoint = path.resolve(tmpDir, 'index.js');
});

Expand Down Expand Up @@ -309,3 +311,207 @@ describe('build (runs slowly)', function () {
should.equal(buildExists, true);
});
});

describe('build in workspaces', function () {
let tmpDir, origCwd;

before(async () => {
tmpDir = getNewTempDirPath();

// Set up a monorepo project structure with two integrations as npm
// workspaces:
//
// (project root)
// ├─ package.json
// └── packages/
// ├─ app-1/
// │ ├─ index.js
// │ └─ package.json
// └─ app-2/
// ├─ index.js
// └─ package.json

// Create root package.json
fs.outputFileSync(
path.join(tmpDir, 'package.json'),
JSON.stringify({
name: 'my-monorepo',
workspaces: ['packages/*'],
private: true,
})
);

const defaultIndexJs = `module.exports = {
version: require('./package.json').version,
platformVersion: require('zapier-platform-core').version,
};`;

// First integration: app-1
fs.outputFileSync(
path.join(tmpDir, 'packages', 'app-1', 'index.js'),
defaultIndexJs
);
fs.outputFileSync(
path.join(tmpDir, 'packages', 'app-1', 'package.json'),
JSON.stringify({
name: 'app-1',
version: '1.0.0',
main: 'index.js',
dependencies: {
uuid: '8.3.2',
'zapier-platform-core': '15.5.1',
},
private: true,
})
);

// Second integration: app-2
fs.outputFileSync(
path.join(tmpDir, 'packages', 'app-2', 'index.js'),
defaultIndexJs
);
fs.outputFileSync(
path.join(tmpDir, 'packages', 'app-2', 'package.json'),
JSON.stringify({
name: 'app-2',
version: '1.0.0',
main: 'index.js',
dependencies: {
uuid: '9.0.1',
'zapier-platform-core': '15.5.1',
},
private: true,
})
);

runCommand('yarn', ['install'], { cwd: tmpDir });
});

after(() => {
fs.removeSync(tmpDir);
});

beforeEach(() => {
origCwd = process.cwd();
});

afterEach(() => {
process.chdir(origCwd);
});

it('should build in app-1', async () => {
const workspaceDir = path.join(tmpDir, 'packages', 'app-1');
const zipPath = path.join(workspaceDir, 'build', 'build.zip');
const unzipPath = path.join(tmpDir, 'build', 'build');

// Make sure the zapier-platform-core dependency is installed in the root
// project directory
fs.existsSync(
path.join(tmpDir, 'node_modules', 'zapier-platform-core')
).should.be.true();
fs.existsSync(
path.join(workspaceDir, 'node_modules', 'zapier-platform-core')
).should.be.false();

fs.ensureDirSync(path.dirname(zipPath));

process.chdir(workspaceDir);

await build.buildAndOrUpload(
{ build: true, upload: false },
{
skipNpmInstall: true,
skipValidation: true,
printProgress: false,
checkOutdated: false,
}
);
await decompress(zipPath, unzipPath);

const corePackageJson = JSON.parse(
fs.readFileSync(
path.join(
unzipPath,
'node_modules',
'zapier-platform-core',
'package.json'
)
)
);
corePackageJson.version.should.equal('15.5.1');

const uuidPackageJson = JSON.parse(
fs.readFileSync(
path.join(unzipPath, 'node_modules', 'uuid', 'package.json')
)
);
uuidPackageJson.version.should.equal('8.3.2');

// Make sure node_modules/app-1 and node_modules/app-2 are not included
// in the build
fs.existsSync(
path.join(unzipPath, 'node_modules', 'app-1')
).should.be.false();
fs.existsSync(
path.join(unzipPath, 'node_modules', 'app-2')
).should.be.false();
});

it('should build in app-2', async () => {
const workspaceDir = path.join(tmpDir, 'packages', 'app-2');
const zipPath = path.join(workspaceDir, 'build', 'build.zip');
const unzipPath = path.join(tmpDir, 'build', 'build');

// Make sure the zapier-platform-core dependency is installed in the root
// project directory
fs.existsSync(
path.join(tmpDir, 'node_modules', 'zapier-platform-core')
).should.be.true();
fs.existsSync(
path.join(workspaceDir, 'node_modules', 'zapier-platform-core')
).should.be.false();

fs.ensureDirSync(path.dirname(zipPath));

process.chdir(workspaceDir);

await build.buildAndOrUpload(
{ build: true, upload: false },
{
skipNpmInstall: true,
skipValidation: true,
printProgress: false,
checkOutdated: false,
}
);
await decompress(zipPath, unzipPath);

const corePackageJson = JSON.parse(
fs.readFileSync(
path.join(
unzipPath,
'node_modules',
'zapier-platform-core',
'package.json'
)
)
);
corePackageJson.version.should.equal('15.5.1');

const uuidPackageJson = JSON.parse(
fs.readFileSync(
path.join(unzipPath, 'node_modules', 'uuid', 'package.json')
)
);
uuidPackageJson.version.should.equal('9.0.1');

// Make sure node_modules/app-1 and node_modules/app-2 are not included
// in the build
fs.existsSync(
path.join(unzipPath, 'node_modules', 'app-1')
).should.be.false();
fs.existsSync(
path.join(unzipPath, 'node_modules', 'app-2')
).should.be.false();
});
});
Loading

0 comments on commit 9e9ece7

Please sign in to comment.