@canva/platform 2.0.0 → 2.1.0
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.
- package/index.d.ts +9 -9
- package/lib/cjs/sdk/platform/fake/create.js +29 -0
- package/lib/cjs/sdk/platform/fake/fake_app_process_client.js +41 -0
- package/lib/cjs/sdk/platform/fake/fake_feature_support_client.js +19 -0
- package/lib/cjs/sdk/platform/fake/fake_platform_client.js +23 -0
- package/lib/cjs/sdk/platform/index.js +1 -2
- package/lib/cjs/sdk/platform/public.js +2 -6
- package/lib/cjs/sdk/platform/test/index.js +16 -0
- package/lib/cjs/sdk/utils/canva_sdk.js +41 -0
- package/lib/esm/sdk/platform/fake/create.js +19 -0
- package/lib/esm/sdk/platform/fake/fake_app_process_client.js +31 -0
- package/lib/esm/sdk/platform/fake/fake_feature_support_client.js +9 -0
- package/lib/esm/sdk/platform/fake/fake_platform_client.js +13 -0
- package/lib/esm/sdk/platform/index.js +1 -2
- package/lib/esm/sdk/platform/public.js +2 -6
- package/lib/esm/sdk/platform/test/index.js +6 -0
- package/lib/esm/sdk/utils/canva_sdk.js +20 -0
- package/package.json +9 -9
- package/test/index.d.ts +11 -0
package/index.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export declare interface AppProcess {
|
|
|
26
26
|
*/
|
|
27
27
|
requestClose<T extends CloseParams>(
|
|
28
28
|
target: AppProcessId,
|
|
29
|
-
params: T
|
|
29
|
+
params: T,
|
|
30
30
|
): Promise<void>;
|
|
31
31
|
/**
|
|
32
32
|
* @public
|
|
@@ -40,7 +40,7 @@ export declare interface AppProcess {
|
|
|
40
40
|
*/
|
|
41
41
|
registerOnStateChange(
|
|
42
42
|
target: AppProcessId,
|
|
43
|
-
callback: OnStateChangeCallback
|
|
43
|
+
callback: OnStateChangeCallback,
|
|
44
44
|
): () => Promise<void>;
|
|
45
45
|
/**
|
|
46
46
|
* @public
|
|
@@ -176,7 +176,7 @@ export declare type CurrentAppProcess = {
|
|
|
176
176
|
* - The complete execution of the callback is not guaranteed as some user actions (e.g. closing tabs) may close the process prematurely.
|
|
177
177
|
*/
|
|
178
178
|
setOnDispose<T extends CloseParams>(
|
|
179
|
-
callback: OnDisposeCallback<T
|
|
179
|
+
callback: OnDisposeCallback<T>,
|
|
180
180
|
): () => Promise<void>;
|
|
181
181
|
};
|
|
182
182
|
|
|
@@ -221,7 +221,7 @@ export declare interface FeatureSupport {
|
|
|
221
221
|
* @public
|
|
222
222
|
* Returns information about the platform on which the app is running.
|
|
223
223
|
*/
|
|
224
|
-
export declare
|
|
224
|
+
export declare const getPlatformInfo: () => PlatformInfo;
|
|
225
225
|
|
|
226
226
|
/**
|
|
227
227
|
* @public
|
|
@@ -229,7 +229,7 @@ export declare function getPlatformInfo(): PlatformInfo;
|
|
|
229
229
|
* @param opts - Parameters passed to the `setOnDispose` callback when a process is about to close.
|
|
230
230
|
*/
|
|
231
231
|
export declare type OnDisposeCallback<T extends CloseParams> = (
|
|
232
|
-
opts: T
|
|
232
|
+
opts: T,
|
|
233
233
|
) => Promise<void>;
|
|
234
234
|
|
|
235
235
|
/**
|
|
@@ -246,7 +246,7 @@ export declare type OnMessageCallback = (
|
|
|
246
246
|
appProcessId: AppProcessId;
|
|
247
247
|
surface: AppSurface;
|
|
248
248
|
},
|
|
249
|
-
message: any
|
|
249
|
+
message: any,
|
|
250
250
|
) => Promise<void>;
|
|
251
251
|
|
|
252
252
|
/**
|
|
@@ -355,8 +355,8 @@ export declare type ProcessState = "opening" | "open" | "closing" | "closed";
|
|
|
355
355
|
*
|
|
356
356
|
* In some browsers, the user must enable popup permissions before any URL can be opened.
|
|
357
357
|
*/
|
|
358
|
-
export declare
|
|
359
|
-
request: OpenExternalUrlRequest
|
|
360
|
-
)
|
|
358
|
+
export declare const requestOpenExternalUrl: (
|
|
359
|
+
request: OpenExternalUrlRequest,
|
|
360
|
+
) => Promise<OpenExternalUrlResponse>;
|
|
361
361
|
|
|
362
362
|
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "createFakePlatformClients", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return createFakePlatformClients;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _fake_app_process_client = require("./fake_app_process_client");
|
|
12
|
+
const _fake_feature_support_client = require("./fake_feature_support_client");
|
|
13
|
+
const _fake_platform_client = require("./fake_platform_client");
|
|
14
|
+
function createFakePlatformClients() {
|
|
15
|
+
const appProcess = new _fake_app_process_client.FakeAppProcessClient();
|
|
16
|
+
const platform = new _fake_platform_client.FakePlatformClient();
|
|
17
|
+
const features = new _fake_feature_support_client.FakeFeatureSupportClient();
|
|
18
|
+
const i18n = undefined;
|
|
19
|
+
return {
|
|
20
|
+
platform: {
|
|
21
|
+
v2: {
|
|
22
|
+
platform,
|
|
23
|
+
appProcess,
|
|
24
|
+
i18n,
|
|
25
|
+
features
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "FakeAppProcessClient", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return FakeAppProcessClient;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
class FakeAppProcessClient {
|
|
12
|
+
async requestClose(target, params) {
|
|
13
|
+
await Promise.resolve();
|
|
14
|
+
}
|
|
15
|
+
registerOnStateChange(target, callback) {
|
|
16
|
+
return async ()=>{
|
|
17
|
+
await Promise.resolve();
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
registerOnMessage(callback) {
|
|
21
|
+
return async ()=>{
|
|
22
|
+
await Promise.resolve();
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
broadcastMessage(message) {}
|
|
26
|
+
constructor(){
|
|
27
|
+
this.current = {
|
|
28
|
+
getInfo: ()=>({
|
|
29
|
+
processId: 'test-process-id',
|
|
30
|
+
surface: 'object_panel'
|
|
31
|
+
}),
|
|
32
|
+
requestClose: async (params)=>{
|
|
33
|
+
await Promise.resolve();
|
|
34
|
+
},
|
|
35
|
+
setOnDispose: (callback)=>async ()=>{
|
|
36
|
+
await Promise.resolve();
|
|
37
|
+
},
|
|
38
|
+
registerOnStateChangeInternal: (callback)=>()=>Promise.resolve()
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "FakeFeatureSupportClient", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return FakeFeatureSupportClient;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
class FakeFeatureSupportClient {
|
|
12
|
+
isSupported(...features) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
registerOnSupportChange(onSupportChange) {
|
|
16
|
+
onSupportChange();
|
|
17
|
+
return ()=>{};
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "FakePlatformClient", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return FakePlatformClient;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
class FakePlatformClient {
|
|
12
|
+
async requestOpenExternalUrl(options) {
|
|
13
|
+
await Promise.resolve();
|
|
14
|
+
return {
|
|
15
|
+
status: 'completed'
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
getPlatformInfo() {
|
|
19
|
+
return {
|
|
20
|
+
canAcceptPayments: true
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -17,5 +17,4 @@ function _export_star(from, to) {
|
|
|
17
17
|
return from;
|
|
18
18
|
}
|
|
19
19
|
var _window___canva___sdkRegistration, _window___canva__;
|
|
20
|
-
(_window___canva__ =
|
|
21
|
-
window.__canva__) === null || _window___canva__ === void 0 ? void 0 : (_window___canva___sdkRegistration = _window___canva__.sdkRegistration) === null || _window___canva___sdkRegistration === void 0 ? void 0 : _window___canva___sdkRegistration.registerPackageVersion('platform', '2.0.0', 'ga');
|
|
20
|
+
(_window___canva__ = window.__canva__) === null || _window___canva__ === void 0 ? void 0 : (_window___canva___sdkRegistration = _window___canva__.sdkRegistration) === null || _window___canva___sdkRegistration === void 0 ? void 0 : _window___canva___sdkRegistration.registerPackageVersion('platform', '2.1.0', 'ga');
|
|
@@ -25,9 +25,5 @@ _export(exports, {
|
|
|
25
25
|
const { canva_sdk } = window;
|
|
26
26
|
const appProcess = canva_sdk.platform.v2.appProcess;
|
|
27
27
|
const features = canva_sdk.platform.v2.features;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
function getPlatformInfo() {
|
|
32
|
-
return canva_sdk.platform.v2.platform.getPlatformInfo();
|
|
33
|
-
}
|
|
28
|
+
const requestOpenExternalUrl = canva_sdk.platform.v2.platform.requestOpenExternalUrl;
|
|
29
|
+
const getPlatformInfo = canva_sdk.platform.v2.platform.getPlatformInfo;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "initTestEnvironment", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return initTestEnvironment;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _create = require('../fake/create');
|
|
12
|
+
const _canva_sdk = require('../../utils/canva_sdk');
|
|
13
|
+
function initTestEnvironment() {
|
|
14
|
+
(0, _canva_sdk.assertIsTestCanvaSdk)();
|
|
15
|
+
(0, _canva_sdk.injectFakeAPIClients)((0, _create.createFakePlatformClients)());
|
|
16
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
getCanvaSdk: function() {
|
|
13
|
+
return getCanvaSdk;
|
|
14
|
+
},
|
|
15
|
+
assertIsTestCanvaSdk: function() {
|
|
16
|
+
return assertIsTestCanvaSdk;
|
|
17
|
+
},
|
|
18
|
+
injectFakeAPIClients: function() {
|
|
19
|
+
return injectFakeAPIClients;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
function getCanvaSdk() {
|
|
23
|
+
return window.canva_sdk;
|
|
24
|
+
}
|
|
25
|
+
function assertIsTestCanvaSdk() {
|
|
26
|
+
var _window___canva__;
|
|
27
|
+
if ((_window___canva__ = window.__canva__) === null || _window___canva__ === void 0 ? void 0 : _window___canva__.uiKit) {
|
|
28
|
+
var _getCanvaSdk_error, _getCanvaSdk;
|
|
29
|
+
const CanvaError = (_getCanvaSdk = getCanvaSdk()) === null || _getCanvaSdk === void 0 ? void 0 : (_getCanvaSdk_error = _getCanvaSdk.error) === null || _getCanvaSdk_error === void 0 ? void 0 : _getCanvaSdk_error.v2.CanvaError;
|
|
30
|
+
throw new CanvaError({
|
|
31
|
+
code: 'failed_precondition',
|
|
32
|
+
message: "Canva App SDK: You're attempting to call `initTestEnvironment` in a non-test environment, such as in production. This method should be called in test environments, once and only once. For more info refer to https://canva.dev/docs/apps/testing/"
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function injectFakeAPIClients(clients) {
|
|
37
|
+
window.canva_sdk = {
|
|
38
|
+
...getCanvaSdk(),
|
|
39
|
+
...clients
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { FakeAppProcessClient } from './fake_app_process_client';
|
|
2
|
+
import { FakeFeatureSupportClient } from './fake_feature_support_client';
|
|
3
|
+
import { FakePlatformClient } from './fake_platform_client';
|
|
4
|
+
export function createFakePlatformClients() {
|
|
5
|
+
const appProcess = new FakeAppProcessClient();
|
|
6
|
+
const platform = new FakePlatformClient();
|
|
7
|
+
const features = new FakeFeatureSupportClient();
|
|
8
|
+
const i18n = undefined;
|
|
9
|
+
return {
|
|
10
|
+
platform: {
|
|
11
|
+
v2: {
|
|
12
|
+
platform,
|
|
13
|
+
appProcess,
|
|
14
|
+
i18n,
|
|
15
|
+
features
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export class FakeAppProcessClient {
|
|
2
|
+
async requestClose(target, params) {
|
|
3
|
+
await Promise.resolve();
|
|
4
|
+
}
|
|
5
|
+
registerOnStateChange(target, callback) {
|
|
6
|
+
return async ()=>{
|
|
7
|
+
await Promise.resolve();
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
registerOnMessage(callback) {
|
|
11
|
+
return async ()=>{
|
|
12
|
+
await Promise.resolve();
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
broadcastMessage(message) {}
|
|
16
|
+
constructor(){
|
|
17
|
+
this.current = {
|
|
18
|
+
getInfo: ()=>({
|
|
19
|
+
processId: 'test-process-id',
|
|
20
|
+
surface: 'object_panel'
|
|
21
|
+
}),
|
|
22
|
+
requestClose: async (params)=>{
|
|
23
|
+
await Promise.resolve();
|
|
24
|
+
},
|
|
25
|
+
setOnDispose: (callback)=>async ()=>{
|
|
26
|
+
await Promise.resolve();
|
|
27
|
+
},
|
|
28
|
+
registerOnStateChangeInternal: (callback)=>()=>Promise.resolve()
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
var _window___canva___sdkRegistration, _window___canva__;
|
|
2
2
|
export * from './public';
|
|
3
|
-
(_window___canva__ =
|
|
4
|
-
window.__canva__) === null || _window___canva__ === void 0 ? void 0 : (_window___canva___sdkRegistration = _window___canva__.sdkRegistration) === null || _window___canva___sdkRegistration === void 0 ? void 0 : _window___canva___sdkRegistration.registerPackageVersion('platform', '2.0.0', 'ga');
|
|
3
|
+
(_window___canva__ = window.__canva__) === null || _window___canva__ === void 0 ? void 0 : (_window___canva___sdkRegistration = _window___canva__.sdkRegistration) === null || _window___canva___sdkRegistration === void 0 ? void 0 : _window___canva___sdkRegistration.registerPackageVersion('platform', '2.1.0', 'ga');
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
const { canva_sdk } = window;
|
|
2
2
|
export const appProcess = canva_sdk.platform.v2.appProcess;
|
|
3
3
|
export const features = canva_sdk.platform.v2.features;
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
export function getPlatformInfo() {
|
|
8
|
-
return canva_sdk.platform.v2.platform.getPlatformInfo();
|
|
9
|
-
}
|
|
4
|
+
export const requestOpenExternalUrl = canva_sdk.platform.v2.platform.requestOpenExternalUrl;
|
|
5
|
+
export const getPlatformInfo = canva_sdk.platform.v2.platform.getPlatformInfo;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { createFakePlatformClients } from '../fake/create';
|
|
2
|
+
import { assertIsTestCanvaSdk, injectFakeAPIClients } from '../../utils/canva_sdk';
|
|
3
|
+
export function initTestEnvironment() {
|
|
4
|
+
assertIsTestCanvaSdk();
|
|
5
|
+
injectFakeAPIClients(createFakePlatformClients());
|
|
6
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function getCanvaSdk() {
|
|
2
|
+
return window.canva_sdk;
|
|
3
|
+
}
|
|
4
|
+
export function assertIsTestCanvaSdk() {
|
|
5
|
+
var _window___canva__;
|
|
6
|
+
if ((_window___canva__ = window.__canva__) === null || _window___canva__ === void 0 ? void 0 : _window___canva__.uiKit) {
|
|
7
|
+
var _getCanvaSdk_error, _getCanvaSdk;
|
|
8
|
+
const CanvaError = (_getCanvaSdk = getCanvaSdk()) === null || _getCanvaSdk === void 0 ? void 0 : (_getCanvaSdk_error = _getCanvaSdk.error) === null || _getCanvaSdk_error === void 0 ? void 0 : _getCanvaSdk_error.v2.CanvaError;
|
|
9
|
+
throw new CanvaError({
|
|
10
|
+
code: 'failed_precondition',
|
|
11
|
+
message: "Canva App SDK: You're attempting to call `initTestEnvironment` in a non-test environment, such as in production. This method should be called in test environments, once and only once. For more info refer to https://canva.dev/docs/apps/testing/"
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export function injectFakeAPIClients(clients) {
|
|
16
|
+
window.canva_sdk = {
|
|
17
|
+
...getCanvaSdk(),
|
|
18
|
+
...clients
|
|
19
|
+
};
|
|
20
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canva/platform",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "The Canva Apps SDK app platform library",
|
|
5
5
|
"author": "Canva Pty Ltd.",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.md FILE",
|
|
@@ -11,14 +11,14 @@
|
|
|
11
11
|
"module": "./lib/esm/sdk/platform/index.js",
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
"types": "./index.d.ts",
|
|
15
|
+
"require": "./lib/cjs/sdk/platform/index.js",
|
|
16
|
+
"import": "./lib/esm/sdk/platform/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./test": {
|
|
19
|
+
"types": "./test/index.d.ts",
|
|
20
|
+
"require": "./lib/cjs/sdk/platform/test/index.js",
|
|
21
|
+
"import": "./lib/esm/sdk/platform/test/index.js"
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
"typings": "./index.d.ts"
|
package/test/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @public
|
|
3
|
+
* Initializes a test environment for the `@canva/platform` package, enabling unit tests to mock Canva's APIs.
|
|
4
|
+
* @remarks
|
|
5
|
+
* This method should only be called once in a test environment, such as in a Jest setup file.
|
|
6
|
+
* @see
|
|
7
|
+
* https://www.canva.dev/docs/apps/testing/
|
|
8
|
+
*/
|
|
9
|
+
export declare function initTestEnvironment(): void;
|
|
10
|
+
|
|
11
|
+
export {};
|